日期:2014-05-18  浏览次数:20555 次

如何获取某一周的第一天和最后一天的日期
一年有52周,如何能获取某一周的第一天和最后一天的日期?

例如现在希望得到2011年第46周的第一天和最后一天的日期

------解决方案--------------------
SQL code

set datefirst 1
select date
from(
    select dateadd(dd,number,'2011-01-01') date
    from master..spt_values
    where [type] = 'p' and number >= 0 and number < datediff(dd,'2011-01-01','2012-01-01')
) t
where datepart(week,date) = 46

------解决方案--------------------
http://topic.csdn.net/u/20091031/15/29aa1b45-23ed-49cd-8aa6-f9297fe95b6e.html
参考#3
------解决方案--------------------

借助AcHerat
#2楼
SQL code

set datefirst 1
select MIN(date) as firstdate,MAX(date) as lastdate from(
select date
from(
    select dateadd(dd,number,'2011-01-01') date
    from master..spt_values
    where [type] = 'p' and number >= 0 and number < datediff(dd,'2011-01-01','2012-01-01')
) t
where datepart(week,date) = 46) a