Get the most recent Friday's date SQL

后端 未结 8 1244
孤城傲影
孤城傲影 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:20

    SELECT CONVERT(VARCHAR(12),GETDATE()) AS Today,
    CASE WHEN (DATEPART(DW,GETDATE())< 7) 
    THEN CONVERT(VARCHAR(12),(DATEADD(dd,-(DATEPART(DW,GETDATE())+1),GETDATE())))
    ELSE CONVERT(VARCHAR(12),(DATEADD(d,- 1,GETDATE())))
    END AS [Last Friday]
    

提交回复
热议问题