考虑以下脚本:
SET LANGUAGE 'German'
GO
SET DATEFIRST 1
GO
DECLARE @FullDate DATETIME
DECLARE @DayofWeek tinyint
DECLARE @relativeWeek int
SELECT @FullDate = '5/1/2008'
WHILE (@FullDate <= '7/1/2008')
BEGIN
SELECT DATEPART (DW , @FullDate) as day_of_week, DATEDIFF(WEEK, CURRENT_TIMESTAMP, @FullDate) as relative_week
SELECT @FullDate = DATEADD(DAY, 1, @Fulldate)
END
目前的结果是
day_of_week relative_week
----------------------------
6 -220
7 -219
1 -219
现在我如何设法得到这样的结果:
day_of_week relative_week
----------------------------
6 -220
7 -220 <-- here's the difference :)
1 -219
意思是在星期一/星期一的第一周开始。如您所见,将datefirst变量设置为1没有效果。
提前致谢。
答案 0 :(得分:3)
希望它有所帮助。
事实上 - DATEDIFF并不关心DATEFIRST