I have had this same issue, and created the following example to show how to do this and to make it flexible to use whichever day of the week you want. I have different lines in the SELECT
statement, just to show what this is doing, but you just need the [Results]
line to get the answer. I also used variables for the current date and the target day of the week, to make it easier to see what needs to change.
Finally, there is an example of results when you want to include the current date as a possible example or when you always want to go back to the previous week.
DECLARE @GetDate AS DATETIME = GETDATE();
DECLARE @Target INT = 6 -- 6 = Friday
SELECT
@GetDate AS [Current Date] ,
DATEPART(dw, @GetDate) AS [Current Day of Week],
@Target AS [Target Day of Week] ,
IIF(@Target = DATEPART(dw, @GetDate), 'Yes' , 'No') AS [IsMatch] ,
IIF(@Target = DATEPART(dw, @GetDate), 0 , ((7 + @Target - DATEPART(dw, @GetDate)) % 7) - 7) AS [DateAdjust] ,
------------------------------------------------------------------------------------------------------------------------------------------------
CAST(IIF(@Target = DATEPART(dw, @GetDate), @GetDate, DATEADD(d, (((7 + @Target - DATEPART(dw, @GetDate)) % 7) - 7), @GetDate)) AS DATE) AS [Result]
------------------------------------------------------------------------------------------------------------------------------------------------
;
SELECT
@GetDate AS [Current Date] ,
DATEPART(dw, @GetDate) AS [Current Day of Week],
@Target AS [Target Day of Week] ,
((7 + @Target - DATEPART(dw, @GetDate)) % 7) - 7 AS [DateAdjust] ,
------------------------------------------------------------------------------------------------------------------------------------------------
CAST(DATEADD(d, (((7 + @Target - DATEPART(dw, @GetDate)) % 7) - 7), @GetDate) AS DATE) AS [NOTIncludeCurrent]
------------------------------------------------------------------------------------------------------------------------------------------------
;