Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 last friday of a given date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 12/27/2012 :  05:51:56  Show Profile  Reply with Quote
Hi,
for a given date i.e. 31 Dec 2012, how can I get the last friday of this date which is: 28 Dec 2012


Thanks

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/27/2012 :  06:30:43  Show Profile  Reply with Quote
DECLARE @dt DATETIME = '20121231'
SELECT DATEADD(dd,-DATEDIFF(dd,-3,@dt)%7,@dt)
Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 12/27/2012 :  07:07:18  Show Profile  Reply with Quote
Many thanks
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 12/27/2012 :  07:12:34  Show Profile  Reply with Quote
--Alternate is
DECLARE @date DATETIME = '20121201' -- Thursday
SELECT DATEADD(DAY,-(DATEDIFF(DAY,'19000105',@date)%7),@date)


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000