Get First Day & Last Day of Last Week

Get First Day & Last Day of Last Week

I have a requirement to generate data for reporting for the previous week, where the week starts on a Monday and ends on a Sunday.The requirement being that Monday begins at midnight and Sunday ends milliseconds before midnight.

I hope that helps!

DECLARE @weekstart DATETIME, @weekend DATETIME 

-- Set the start of the week as a Monday 
SET DATEFIRST 1 

SELECT 
  @weekstart = DATEADD(wk, DATEDIFF(wk, 0, GETDATE()) - 1, 0), 
  @weekend = DATEADD(ms, -3,DATEADD(wk,DATEDIFF(wk,7,GETDATE()),7))
Mike250

I'm an Australian Chief Analytics Officer passionate about data science, visual insights, and all things sportโ€”particularly cricket. An adventurer at heart, Iโ€™ve gone from abseiling cliffs to snorkeling in crystal-clear waters, sleeping in the wilds of Africa, and exploring destinations worldwide, with my latest trip taking me to Bali. When I'm not diving into data or analytics, I'm spending time with my three sons and two daughters, attempting to hit sixes for my local cricket club, reviewing chicken schnitzels or honing my craft around a coffee machine.

Related Posts
Leave a comment

Your email address will not be published. Required fields are marked *