MySQL Get a list of dates in month, year

前端 未结 2 1204
面向向阳花
面向向阳花 2021-01-13 02:23

I am doing some reports and I want to get all dates in specific month, for example January 2014, and when I do this \'SQL\':

SELECT datesInMonth WHERE month          


        
2条回答
  •  清歌不尽
    2021-01-13 02:54

    You can use the datetime function in MySQL. In particular, MONTH() and YEAR(). If you pass a date into those functions, it'll return the month or year. For example:

    WHERE MONTH(my_date) = 2 and YEAR(my_date) = 2014
    

    If you want to get all of the dates in a month, you can do something like this:

    SELECT my_date FROM my_table
    WHERE MONTH(my_date) = 2 and YEAR(my_date) = 2014
    

提交回复
热议问题