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 2005 Forums
 Transact-SQL (2005)
 previous Week 's date

Author  Topic 

konark
Yak Posting Veteran

60 Posts

Posted - 2009-05-01 : 14:25:47
in sql server the week start in sunday or monday ?
what will be the date , 6 weeks before ?

like today is 20090501 in yyyymmdd format
then i want the output as 20090316 or 20090315 .

Chandragupta Mourya

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-01 : 14:33:42
DECLARE @Date datetime set @date = '20090501'

select dateadd(week,datediff(week,0,dateadd(week,-6,@date)),0)

Jim
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2009-05-01 : 14:37:32
I dont want to use any variable.. can i use getdate() some how?

Chandragupta Mourya
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-01 : 15:16:59
I used a variable for demonstration, just replace it with getdate().

Jim
Go to Top of Page
   

- Advertisement -