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

前端 未结 6 1909
独厮守ぢ
独厮守ぢ 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:22

    Week of month (where the starting incomplete week is counted as a whole)

    select ceiling((day(now()) - 
    (6 - weekday(date_format(now(),'%Y-%m-01'))))/7) 
    + case when 6 - weekday(date_format(now(),'%Y-%m-01'))> 0 
    then 1 else 0 end week_of_month;
    

提交回复
热议问题