mysql - How to get data by date range given only month and year

前端 未结 5 660
轮回少年
轮回少年 2021-01-15 16:18

Below is my mysql table:

--------------------------
ID  Date_From   Date_To
--------------------------
1   2011-02-01  2011-02-28
2   2012-09-01  2012-09-30
         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 16:53

    You need to use query like this:

    SELECT * FROM TIME_PERIOD WHERE 
    (YEAR(DATE_FROM) >= '2013' OR (YEAR(DATE_FROM) >= '2012' AND
     MONTH(DATE_FROM) >= '10')) AND 
    (YEAR(DATE_TO) <= '2013' AND MONTH(DATE_TO) <= '12');
    

提交回复
热议问题