如果我给出的日期为 2015-12-31,它必须显示为
2015W53, for 2015-12-31, which means Week 53, and next follows as
2016W1, Next as
2016W2, Next as
2016W3 Next as...
我的逻辑是
DECLARE @WEEK VARCHAR(2), @YEAR VARCHAR(4)
SELECT @YEAR = DATEPART(YY,@DATE), @WEEK = CAST(DATEPART(WK,@DATE) AS INT) % 52 ;
IF(CAST(DATEPART(WK,@DATE) AS INT) % 52 = 0)
SET @WEEK = 52;
IF(CAST(DATEPART(WK,@DATE) AS INT) = 53)
SET @YEAR = CAST(@YEAR AS INT) + 1;
IF (LEN(@WEEK) < 2)
BEGIN
SET @WEEK = LEFT('0' + @week, 2)
END
RETURN @YEAR + @WEEK
但是这里2015W53不见了,接下来 9 周,
我也只想要一年中的最后一周..,尝试了很多次但无法获得。任何帮助都非常感谢。