SELECT MySQL rows where today's date is between two DATE columns

前端 未结 4 1180
粉色の甜心
粉色の甜心 2021-02-05 20:27

How can I get the rows in a table where today\'s date is between (inclusive) two DATE columns of that row? For example, take these two columns of a table:

4条回答
  •  粉色の甜心
    2021-02-05 20:57

    You will find a lot of people using between operator, but I prefer using a simple AND operator.

    I do that because although the between operator IS inclusive, simple dates (2012-04-10) can be counted as being midnight, and will thus not be inclusive.

    So this should work just fine and will always include the boundaries of the date range:

    SELECT * FROM table WHERE from_date <= '2012-04-10' AND to_date >= '2012-04-10'
    

提交回复
热议问题