Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with Date values

Status
Not open for further replies.

tektipsismyfavorite

Technical User
May 4, 2006
57
US
I have a cron job setup to run every minute and I want it to retrieve records for that minute. My query is setup like this:
SELECT *
FROM stuff
WHERE datetime >= '".$startdate."'
AND datetime <= '".$enddate."'

startdate and enddate get the current date/time and format it in the MySQL Date Format (YYYY-MM-DD HH:MM:SS).

Well, I put some sample data in the table and waited for my cron to execute, but it didn't work (it notifies me by email).

I then manually entered the data of:
SELECT *
FROM dates
WHERE date >= '2006-06-26 00:00:00'
AND date <= '2006-06-26 23:59:59'

and that worked fine. It pulled all results for 6/26/06.

But when I try:
I then manually entered the data of:
SELECT *
FROM dates
WHERE date >= '2006-06-26 11:48:00'
AND date <= '2006-06-26 11:48:59'

It doesn't get the records for the minute of 11:48. Some sample data, for example would be:
date = 2006-06-26 11:48:02 or
date = 2006-06-26 11:48:20 or
date = 2006-06-26 11:48:00

So, is there something wrong with how I'm finding the time?

My server is 2 hours off my time zone, so I even setup sample data for 2 hours before to see if that were the problem. What am I doing wrong?
 
Here is a better way of writing this would be to use the BETWEEN operator.
Code:
SELECT * FROM dates
WHERE date BETWEEN '2006-06-26 00:00:00' AND '2006-06-26 23:59:59'

M. Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top