Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 urgent matter regarding date

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-11-03 : 07:47:53
Ellin writes "i have the inputs:
1) week number, eg. week 44
2)day , eg monday

Is there anyway for me to get the date for week 44's monday???"

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2003-11-03 : 08:24:34
I believe this will work.




declare @whatday varchar(20),
@whatweek int,
@whatyear char(4)

set @whatday = 'monday'
set @whatweek = 44
set @whatyear = '2003'

declare
@dayofweek int,
@firstofyear datetime

set @firstofyear = convert(datetime,'1/1/' + @whatyear)

select @dayofweek =
case when @whatday = 'monday' then 2
when @whatday = 'tuesday' then 3
when @whatday = 'wednesday' then 4
when @whatday = 'thursday' then 5
when @whatday = 'friday' then 6
when @whatday = 'saturday' then 7
when @whatday = 'sunday' then 1
end

select dateadd(dd,(datepart(weekday,(dateadd(ww,@whatweek,@firstofyear))) - @dayofweek)*-1,dateadd(ww,@whatweek,@firstofyear))
Go to Top of Page
   

- Advertisement -