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
 General SQL Server Forums
 Script Library
 last wednesday date from a given date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dharini
Starting Member

1 Posts

Posted - 12/04/2011 :  01:55:15  Show Profile  Reply with Quote
please let me know how to find last wednesday date

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 12/04/2011 :  02:01:57  Show Profile  Reply with Quote
below will give you last wednesday

select dateadd(dd,datediff(dd,0,getdate())/7 * 7 + 2,0)


if you replace getdate with any date you will get previous wednesday from that date
ex.

select dateadd(dd,datediff(dd,0,'2011-11-14')/7 * 7 + 2,0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jeffw8713
Aged Yak Warrior

USA
806 Posts

Posted - 12/04/2011 :  09:16:58  Show Profile  Reply with Quote
This also works:


 Select datename(weekday, 2)
        ,dateadd(week, datediff(week, 2, getdate()) - 1, 2);


Change the '- 1' to any value to go back/forward that number of weeks.

Jeff
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.03 seconds. Powered By: Snitz Forums 2000