In MySQL, how to return the week of the month?

前端 未结 6 1898
独厮守ぢ
独厮守ぢ 2020-12-10 15:17

The year is divided into 12 months. We can break down a month in four weeks.

In MySQL, how to return the week of the month? (Example: first week: 2 entries, second w

6条回答
  •  既然无缘
    2020-12-10 15:42

    Use the MySQL built-in function week to find the week number for the year, then subtract the week number for the first day of the month.

    SELECT WEEK('2012-02-20') - WEEK('2012-02-01')
    

    there are plenty of options in the documentation to customize the call to fit exactly what you are looking for, but I hope my example gives you an idea of what is available to you.

    http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week

提交回复
热议问题