comparing dates by month and year in mysql

前端 未结 4 1946
醉话见心
醉话见心 2021-02-13 18:11

I have a table containing data about events and festivals with following columns recording their start and end dates.

  • Start_Date
  • End_Date

d

4条回答
  •  难免孤独
    2021-02-13 18:38

    DateTime functions are your friends:

    SELECT
        *
    FROM
        `event`
    WHERE
        (MONTH(NOW()) = MONTH(`Start_Date`))
        AND
        (`End_Date` <= (NOW() + INTERVAL 30 DAY))
        AND
        (YEAR(NOW()) = YEAR(`Start_Date`))
    

提交回复
热议问题