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

  • Comparable thread some time ago. You have to do some calculation with DATEPART and DATEADD and stuff.

    You should use DATEPART(wd, <<first of your month>>) to get the weekday of the first of the month, and use that to calculate the first sunday.

    Something along the lines of

    
    
    if DATEPART(wd, "12/01/2003) = 0
    return "12/01/2003"
    else
    return DATEADD(dd, "12/01/2003", 7-DATEPART(wd, "12/01/2003"))

    For the last, you do comparable arithmetic but backwards ...