sql-server

SQL Server - get next Friday in DATETIME


To get the last Friday of any date the query follows:

SELECT DATEADD(d,-1-(DATEPART(dw,GETDATE()) % 7),GETDATE())

How can I get the next friday?


Solution

  • I've updated this answer to a similar question which takes @@DATEFIRST into consideration:

    EDIT/CORRECTION:

    SELECT DATEADD(DAY, 13 - (@@DATEFIRST + (DATEPART(WEEKDAY,GETDATE()) %7)), GETDATE())