SoulieBaby SoulieBaby - 1 year ago 73
MySQL Question

How to check if a date is between date1 and date2 using mysql?

I'm trying to write a query that will check today's date against my table columns date1 and date2 in mysql/php.. This is what I'm after:

'events' table:

  • date1 = start date (XXXX-XX-XX)

  • date2 = end date (XXXX-XX-XX)


  • select * from events where 2012-01-18 between date1 and date2 (or equal to date1 and date2)

But I'm not sure how to go about it.. any help would be appreciated :)


Maybe I was unclear.. if todays date = '2012-01-18' I need it to find results if today's date is between the date range of date1 and date2.. So date1 may be '2012-01-04' and date2 may be '2012-01-21'.. so if todays date falls between or on those dates, a result is returned..

Answer Source
SELECT * FROM events 
  WHERE date1<='2012-01-18'
  AND date2>='2012-01-18'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download