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
 General SQL Server Forums
 New to SQL Server Programming
 date functions

Author  Topic 

smithani
Starting Member

42 Posts

Posted - 2007-09-11 : 22:11:40
Hi All,
I need to do this.

For ex:'2007-02-28' is the firstdate I have
and 02-28-2007 is a Wednesday..

I need the nextdate to be a Wednesday and for next year
like 02-27-2008 which is also a wednesday.

so far I have this much.but I am stuck

declare @firstdate datetime,@newdate datetime

set @firstdate ='2007-02-28'

set @newdate=dateadd(mm, 12, @nextdate)
select @newdate

select datename(dw,@firstdate) as one
select datename(dw,@newdate) as two

How do i proceed from here.
Thanks for any input

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-11 : 22:22:52
[code]DECLARE @firstdate datetime,
@newdate datetime

SELECT @firstdate = '2007-02-28',
@newdate = DATEADD(week, 52, @firstdate)

SELECT firstdate = @firstdate,
firstdate_wd = DATENAME(weekday, @firstdate),
newdate = @newdate,
newdate_wd = DATENAME(weekday, @newdate)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -