Week() function in sql script

本秂侑毒 提交于 2020-01-11 10:32:17

问题


I am using sql server 2005. I just want to know is there something we can get the week number for the particular month. Example Date = '2008-10-16' Is there something we can have SELECT WEEK(Date). Or any better suggestion.


回答1:


select (datepart(dd,'2008-10-08')-1) / 7 + 1



回答2:


You can do it this way:

SET @weeksinmonth=datediff(week, @date, @lastdate) + 1

That is a copy-and-paste out of one of my stored procedures.




回答3:


SELECT DATEPART( week, '2008-10-16')


来源:https://stackoverflow.com/questions/203118/week-function-in-sql-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!