dadamssg87 Posted May 25, 2011 Share Posted May 25, 2011 i have table in my db that has rows of dates, for example... id | date | created | display | group | 1 | 2011-05-21 00:00:00 | 2011-05-24 20:00:00 | Y | 20 | 2 | 2011-05-22 00:00:00 | 2011-05-24 22:00:00 | N | 20 | 3 | 2011-05-23 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 4 | 2011-05-24 00:00:00 | 2011-05-26 22:00:00 | N | 20 | 5 | 2011-05-25 00:00:00 | 2011-05-30 22:00:00 | N | 20 | I'm trying to query dates that fall on or between two dates. So if i input "2011-05-21 00:00:00" and "2011-05-24 00:00:00" rows 1-4 would be pulled up. I've never used between and can't figure it out. The following query pulls up nothing SELECT * FROM `Exceptions` WHERE 'date' BETWEEN '2011-05-21 00:00:00' AND '2011-05-24 00:00:00' and neither does this one ELECT * FROM `Exceptions` WHERE date('date') BETWEEN date('2011-05-21 00:00:00') AND date('2011-05-24 00:00:00') Quote Link to comment https://forums.phpfreaks.com/topic/237448-help-with-between-query/ Share on other sites More sharing options...
mikosiko Posted May 25, 2011 Share Posted May 25, 2011 try using backtics here: WHERE 'date' BETWEEN should read WHERE `date` BETWEEN Quote Link to comment https://forums.phpfreaks.com/topic/237448-help-with-between-query/#findComment-1220163 Share on other sites More sharing options...
The Little Guy Posted May 25, 2011 Share Posted May 25, 2011 SELECT * FROM `Exceptions` WHERE `date` BETWEEN '2011-05-21 00:00:00' AND '2011-05-24 23:59:59' I don't know how your table will store the data, but you may want to include everything till the end of the day which is why you should note the time for the second date. If not, keep them as 0's Quote Link to comment https://forums.phpfreaks.com/topic/237448-help-with-between-query/#findComment-1220193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.