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
 Other SQL Server Topics (2005)
 date function

Author  Topic 

onlyforme
Starting Member

25 Posts

Posted - 2010-10-22 : 04:19:24
Hi friends,
I need to get a date which is 4 days behind the current date.The main thing is that the previous 4 days are without counting Saturday's and Sunday's. Can any one help me please .Its urgent

thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-22 : 05:12:48
This?
SELECT
CASE
WHEN DATENAME(dw,(DATEADD(d,-4,GETDATE()))) = 'Sunday'
THEN DATEADD(d,-6,GETDATE())
WHEN DATENAME(dw,(DATEADD(d,-4,GETDATE()))) = 'Saturday'
THEN DATEADD(d,-5,GETDATE())
ELSE
DATEADD(d,-4,GETDATE())
END as DatePreviousFour



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -