find the last month last friday date

  • Can some please help me how to find the last month last friday date. Thanks mcuh

  • The main issue is finding last fridays data - you could use datepart(dw - but that will depend on the settings.

    Safer is to count back

    Also do you mean the previous friday 1 month ago or 1 month before the friday before today. I'll assume that you want a friday so the formet.

    daclare @d datetime

    select @d = dateadd(mm,-1,getdate()-1)

    while datename(dw,@d) <> 'Friday'

    select @d = @d - 1

    if you want a single statement

    ;with cte as

    (

    select d = dateadd(mm,-1,getdate()-1), seq = 1

    union all

    select d = cte.d-1 from cte where seq < 7

    )

    select d

    from cte

    where datename(dw,d) = 'Friday'


    Cursors never.
    DTS - only when needed and never to control.

  • I have used the below sql to get the previous month last friday. How ever when am trying to check for next month its giving 24th dec as last friday but it should be 31st dec.

    Please correct me the SQL where i missed

    select CONVERT(char(10),dateadd(day, -7+(6-datepart(weekday,dateadd(month, datediff(month, -1, getdate())-1, 0)))%7,

    dateadd(month, datediff(month, -1, getdate())-1, 0)),101)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply