日期:2014-05-19  浏览次数:20442 次

请问Microsoft outlook 里面某年的第一周起始日期是怎么计算的?谢谢.
请问Microsoft   outlook   里面某年的第一周起始日期是怎么计算的?

能给个算法吗?   谢谢.

------解决方案--------------------
我先按照规则修正算法,再给你讲述算法
set datefirst 1 --设置数据库系统的一周的第一天是星期一
dateadd(dd,-datepart(dw, '2008 ')+1, '2008 ')

测试结果
2007: 2007-01-01
2008: 2007-12-31
2009: 2008-12-29
2010: 2009-12-28
2011: 2010-12-27
2012: 2011-12-26
2013: 2012-12-31
2014: 2013-12-30
2015: 2014-12-29
2016: 2015-12-28
2017: 2016-12-26
2018: 2018-01-01
2019: 2018-12-31

SET DATEFIRST 1
DECLARE @CYEAR VARCHAR (100)
SET @CYEAR= '2007 '
DECLARE @THEYEAR INT;
SET @THEYEAR =CONVERT(INT,@CYEAR)
WHILE @THEYEAR <2020
BEGIN
SET @CYEAR=CONVERT(VARCHAR(100),@THEYEAR)
PRINT @CYEAR + ': ' +CONVERT(VARCHAR(10),DATEADD(DD,-DATEPART(DW,@CYEAR)+1,@CYEAR),120);
SET @THEYEAR=@THEYEAR+1
END