Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate previous date question

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
I need to pull the previous Friday's date..

So, if today is Tuesday 8/31, i need to calculate the previous Friday's date (8/27).

Any suggestions?
 
How to get last Friday's date, without using a calendar table and regardless of the current DATEFIRST setting?
SELECT DATEADD(day, (DATEDIFF (day, '20000107', CURRENT_TIMESTAMP) / 7) * 7, '20000107')
or
SELECT DATEADD(day, (DATEDIFF (day, '20000108', CURRENT_TIMESTAMP) / 7) * 7, '20000107')
The first will return the current day if run on friday, the latter will return the previous friday.

From

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top