SQLTeam.com | Weblogs | Forums

Get a Specific Date


#1

I need to get the date for the previous Friday to the current date , but if current date is Friday then return current date ie;

Today (T) , Prev Friday (F)

T = 05/02/2017 then F = 03/02/2017
T = 03/02/2017 then F = 03/02/2017
T = 02/02/2017 then F = 27/01/2017


#2

DECLARE @date date
SET @date = GETDATE()

SELECT DATEADD(DAY, -DATEDIFF(DAY, 4, @date) % 7, @date) AS MostRecentFriday


#3

Perfect, Thank you