Jump to content

help with between query


dadamssg87

Recommended Posts

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')

 

Link to comment
https://forums.phpfreaks.com/topic/237448-help-with-between-query/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.