Last 30 days

SELECT 

    MIN(CalendarDate) AS StartDate

FROM (

    SELECT 

        TOP 30 

        DATEADD(DAY, -n, CAST(GETDATE() AS DATE)) AS CalendarDate

    FROM (

        SELECT 

            ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n

        FROM 

            sys.objects

    ) AS Numbers

    WHERE 

        DATEPART(WEEKDAY, DATEADD(DAY, -n, CAST(GETDATE() AS DATE))) NOT IN (1, 7) -- 1 = Sunday, 7 = Saturday

    ORDER BY 

        CalendarDate DESC

) AS Last30WorkingDays;

Comments

Popular posts from this blog

host

Steps to create SSH key from git bash

test