不多說直接上code
DECLARE @CurrDay DATETIME=GETDATE()
--SET @CurrDay=CAST(('2013-01-10')AS DATETIME)
--SET @CurrDay=CAST(('2012-01-10')AS DATETIME)
DECLARE @CurrWK INT=DATEPART(wk,@CurrDay)
DECLARE @YearFisrtDay DATETIME=CAST((DATENAME(yy,@CurrDay)+'-01-01') AS DATETIME)
PRINT @YearFisrtDay
--這一年的第一天是星期幾
DECLARE @YearFistWK INT=DATEPART(dw,@YearFisrtDay)
PRINT @YearFistWK
--總多少天 -第一天是屬於的周
PRINT DATEADD(DAY,(@CurrWK-1)*7-@YearFistWK+1,@YearFisrtDay)
