Home Forums SQL Server 2008 T-SQL (SS2K8) get the first date and weekday of every month in a year RE: get the first date and weekday of every month in a year

  • vamsikrishnacheruku (3/10/2014)


    hai i want to get the first date and weekday of every month in a year .

    1/jan/2014, monday

    1/feb/2014,thrusday

    , ,

    ,,

    ,,

    ,,,

    ,,,

    ,,

    1/nov/2014, thrusday

    1/dec/2014, friday

    like this output should be

    Can someone explain to me the weekdays? From what is posted above, it doesn't make any sense.

    I ask because if you want the First of each month and the day it falls on, I cam up with this. Sorry Jeff, only coded it for a single year.

    declare @Year date = getdate();

    with TwelveCount(n) as (select n from (values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12))dt(n))

    select

    dateadd(month,n - 1, dateadd(year,datediff(year,0,@Year),0)) FirstOfMonth,

    datename(dw,dateadd(month,n - 1, dateadd(year,datediff(year,0,@Year),0))) NameOfDay

    from

    TwelveCount

    order by

    dateadd(month,n - 1, dateadd(year,datediff(year,0,@Year),0))