Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 urgentthanks
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2010-10-22 : 05:12:48
This?
SELECTCASE 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.