Get the most recent Friday's date SQL

后端 未结 8 1219
孤城傲影
孤城傲影 2021-02-13 00:48

I\'m trying to get the most recent Friday in SQL Server 2008.

I have this. It gets the beginning of the week (monday) then subtracts 3 days to get Friday.



        
8条回答
  •  后悔当初
    2021-02-13 01:26

    This is what I got I hope it helps

    DECLARE @UserDate DateTime
    SET @UserDate = '2020-09-03'
    SELECT DATEADD(day, (6 - datepart(weekday, @UserDate)) , @UserDate)
    

提交回复
热议问题