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

后端 未结 22 1980
没有蜡笔的小新
没有蜡笔的小新 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:35

    Check this out... its working fine.

    declare @date as datetime = '2014-03-10'
    select DATEPART(week,@date) - DATEPART(week,cast(cast(year(@date) as varchar(4))+'-' + cast(month(@date) as varchar(2)) + '-01' as datetime))+1
    

提交回复
热议问题