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
 General SQL Server Forums
 Script Library
 last wednesday date from a given date

Author  Topic 

dharini
Starting Member

1 Post

Posted - 2011-12-04 : 01:55:15
please let me know how to find last wednesday date

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-04 : 02:01:57
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

819 Posts

Posted - 2011-12-04 : 09:16:58
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
   

- Advertisement -