Get the first day of the week from a week number

There's a feature in SQL that allows you to get the week number of a date. This is usefull in grouping all the detail in a query by week.

So, now you need to report on the first day of the week. This snippet will give you the first day of the week for a given week number.

In the example we're using the Project Cost transaction table... but any table with a date will do.

 

select  padt, -- this is the date
        datepart(wk,padt)  ,-- this is the week number
        CONVERT(varchar(50), (DATEADD(dd, @@DATEFIRST - DATEPART(dw, padt)-6, padt)), 101), -- this returns the first day of the week
        CONVERT(varchar(50), (DATEADD(dd, @@DATEFIRST - DATEPART(dw, padt)  , padt)), 101)  -- this returns the last day of the week
    from pa11801
    group by padt order by 1

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences