sql日期操作
----------------------------------------------------------------------------------------------------------------
--取得日期所在周的第一天
----------------------------------------------------------------------------------------------------------------
SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),-1)
----------------------------------------------------------------------------------------------------------------
--根据年和周,取得所在周的第一天
----------------------------------------------------------------------------------------------------------------
declare @CurWeek nvarchar(10) = '2013_2';
declare @Date datetime;
declare @Week int;
set @Week = convert(int,substring(@CurWeek,6,2));
declare @Year varchar(4);
set @Year = left(@CurWeek,4);
--当年的第一天
select @Date = dateadd(wk,@Week-1,@Year);
--select dateadd(dd,1-datepart(dw,@Date),@date),dateadd(dd,7-datepart(dw,@Date),@Date)
declare @WeekFstDate varchar(10);
set @WeekFstDate = convert(varchar(10),dateadd(dd,1-datepart(dw,@Date),@Date),120);
select @WeekFstDate;