first date of a specified week

  • Hallo friends

    How can I find the first date of current week.

    Eg

    Today is '2003-05-14'

    First date of this week '2003-05-11'

    Best regards

  • Use the following formula

    
    
    DATEADD(dd, 1 - DATEPART(wd, GETDATE()), GETDATE())

    Fiddle around with the '1 minus' part and SET DATEFIRST to determine what the first day of the week should be...

  • Just a correction there wd should read dw.

    DATEADD(dd, 1 - DATEPART(dw, GETDATE()), GETDATE())

    However if you want to always get the Sunday date without having to do anything more in your code and no need to worry about datefirst value then do

    (note this also sets the time value of the date to midnight Sunday. To get Monday use 0 instead of -1, Tuesday use 1 and so on).

    DATEADD(wk, DATEDIFF(wk,-1,GETDATE()), -1)

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

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