How to get week number of the month from the date in sql server 2008

后端 未结 22 1975
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 15:52

In SQL Statement in microsoft sql server, there is a built-in function to get week number but it is the week of the year.

Select DatePart(week, \'2012/11/30\         


        
22条回答
  •  没有蜡笔的小新
    2020-11-27 16:55

    WeekMonth = CASE WHEN (DATEPART(day,TestDate) - datepart(dw,TestDate))>= 22 THEN '5' 
                     WHEN (DATEPART(day,TestDate) - datepart(dw,TestDate))>= 15 THEN '4' 
                     WHEN (DATEPART(day,TestDate) - datepart(dw,TestDate))>= 8 THEN '3'
                     WHEN (DATEPART(day,TestDate) - datepart(dw,TestDate))>= 1 THEN '2' 
                     ELSE '1'
                 END 
    

提交回复
热议问题