Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Working Backwards with Dates


Message #1 by "Carolyn Friedberg" <cfriedberg@c...> on Fri, 25 Oct 2002 15:37:49
Don't know if I'm overthinking or underthinking this one.  Of course I'll 
think of a better way a month from now...but this should work if I 
understand what you're looking for.
 
create proc testproc 
@day int,
@week int,
@year int
as
set nocount on
declare @datevar datetime
 
create table #temp
( date datetime )
 
set @datevar = convert(datetime,'1/1/'+convert(varchar,@year))
while @datevar < convert(datetime,'1/1/'+convert(varchar,@year+1))
begin
 insert into #temp
 select @datevar
 set @datevar = @datevar+1
end
 
select date from #temp where datepart(ww,date) = @week and datepart
(dw,date) = @day
 
drop table #temp

Let us know if this was what you were after.
 
Dan

> I know the week number and the year and also the DateFirst value.

> Now I want the know the actual date from these values.

> How do I do it?

> This has to be dynamic.

> Thank you,
C> arolyn

  Return to Index