开发者

Get week number from dates in T-SQL

How do I ge开发者_运维问答t the week number from dates in T-SQL?


Have a look at DATEPART

SELECT DATEPART(wk, GETDATE())


It is best to use the following:

select DATEPART(ISO_WEEK, getDate())

As when you have a year with a week 53 as in the case of 2015 it give unreliable results. (Certainly on 2008 R2)

select DATEPART(WK, '01/03/2016')

Gives variable results around week 53. When run the week after 3rd Jan it produced the value 1. When run now for the same date it gives the value 2.


Or use DATEDIFF like this: DATEDIFF(wk,GETDATE(),GETDATE()+7) to find the number of weeks between two days

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜