Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.