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 

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

Australian. Sport. Passionate Cricket Fan. Go Pro. Abseiling. Snorkeling. Travel. Golf R. SQL Server Developer. Three sons. One daughter. Last Trip: New York.

Related Posts
Leave a comment

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