Question : Using T-SQL Need to return first day of the 34th week last year.

I need to calculate what the date was for the first day of the 34th week of last year. This so I can compare week 34 last year to this week (also week 34).

I am using Sql Server 2005.

Answer : Using T-SQL Need to return first day of the 34th week last year.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
drop function dbo.weekXMonday
go
create function dbo.weekXMonday(@year int, @weekno int)
returns datetime as
begin
declare @d datetime
set @d=dateadd(yy, @year-1900, 0)
return (dateadd(wk,@weekno-1,@d)-((datepart(dw,@d-2)+@@datefirst)%7))
return @d
end
GO
select dbo.weekXMonday(2009,34)
select dbo.weekXMonday(2010,34)
Random Solutions  
 
programming4us programming4us