Home Forums SQL Server 7,2000 T-SQL First Sunday and Last Sunday in a Month RE: First Sunday and Last Sunday in a Month

  • This will give the first Sunday of the given month of the given year. For the last Sunday do something similar.

    DECLARE @month TINYINT

    , @year SMALLINT

    , @date DATETIME

    SELECT @month = 8

    , @year = 2003

    SET @date = CAST( CAST( @month AS VARCHAR ) + '/01/' + CAST( @year AS VARCHAR ) AS DATETIME )

    SELECT @date

    , DATEPART ( weekday , @date )

    , @date + ( 7 - DATEPART ( weekday , @date ) + 1 ) % 7