Welcome to the iTechForums.
If this is your first visit, be sure to check out the
FAQ by clicking the link above.
You may have to
register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
To register now click here.
|
Latest Threads
Advertisements
Forum Statistics
Threads:
Posts: 3
Members:
Number of Users Online:
Welcome to our newest member, |
|
 |

05-15-2008, 02:33 PM
|
|
Junior Member
|
|
Join Date: May 2008
Posts: 5
|
|
MySQL query date ranges?
I'm trying to pull records from a range of datetime fields. The results are coming together as expected, however the high range doesn't display any results. So if I query records between 2008-05-04 and 2008-05-08 the records stop without displaying the 2008-05-08 records, however anything beween 05 and 07 will show up...weird.
Here's my query, i've tried many variations and they all have the same result
SELECT * FROM timecard WHERE time_in >= '2008-05-03' AND time_in <= '2008-05-08'
I could put a bump into my php to add a day to the date, but I'd rather figure out what I'm doing wrong and fix it within the query
any help will be much appreciated - thanks!
|

05-15-2008, 02:34 PM
|
|
Junior Member
|
|
Join Date: May 2008
Posts: 14
|
|
|
|

05-15-2008, 02:39 PM
|
|
Junior Member
|
|
Join Date: May 2008
Posts: 8
|
|
It looks like your time_in field is DATETIME, which means that all values falling into May 8, will not match by original condition, because the engine casts 2008-05-08 to "2008-05-08 00:00:00" before it can compare the value to your time_in (i.e. midnight on that date).
You got to change your query to this:
SELECT * FROM timecard WHERE time_in >= '2008-05-03 00:00:00' AND time_in <= '2008-05-08 23:59:59'
Or, add 1 day to the upper limit, as you suggested yourself.
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
All times are GMT. The time now is 08:14 PM.