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
精彩评论