markkanning Posted September 21, 2007 Share Posted September 21, 2007 Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this: SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00' But if I compare 2 dates spanning a day, or multiple days, I get nothing. Any thoughts? Mark Link to comment https://forums.phpfreaks.com/topic/70216-solved-comparing-dates-in-query-with-between/ Share on other sites More sharing options...
teng84 Posted September 22, 2007 Share Posted September 22, 2007 Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this: SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00' But if I compare 2 dates spanning a day, or multiple days, I get nothing. Any thoughts? Mark be glad you get nothing or else MYSQL means error lol u use now on your condtion right so its like having a range of 2007-09-21 03:00:00' to 2007-09-21 03:00:00' i guess what you mean is SELECT * FROM table WHERE FIELDHERE BETWEEN '2007-09-21 03:00:00' AND now() Link to comment https://forums.phpfreaks.com/topic/70216-solved-comparing-dates-in-query-with-between/#findComment-352797 Share on other sites More sharing options...
fenway Posted September 24, 2007 Share Posted September 24, 2007 Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this: SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00' But if I compare 2 dates spanning a day, or multiple days, I get nothing. Any thoughts? Mark In general, you would try to put your field value outside the "between", so that an index could be used... Link to comment https://forums.phpfreaks.com/topic/70216-solved-comparing-dates-in-query-with-between/#findComment-354040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.