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

前端 未结 6 2105
醉梦人生
醉梦人生 2021-01-03 03:49

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:

6条回答
  •  萌比男神i
    2021-01-03 04:24

    Though there are many answers available to this question I would like to give my response regarding the same situation I faced.

    I am using php to query mysql database.

    first what I do is to convert the date in the mysql supported date format which is yyyy-mm-dd

    $date = new DateTime($date);
    $date=date_format($date, 'Y-m-d');
    

    in the query's where clause I use BETWEEN

    "'$date' BETWEEN start_date AND end_date"
    

    this works perfectly given the case described here.

提交回复
热议问题