Over the next few days we are going to start the migration to a new forum application. I'm going to start with high post count and active users. You may receive an invitation to the new forums. It's not spam. It's just me trying to seed the user base. My goal is to open it up over the weekend.

Once we open the site we'll block registrations here. We should be open shortly on the new site.

SQL Server Forums
Profile | Register | 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
 New Topic  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  
 New 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.2 seconds. Powered By: Snitz Forums 2000