Some Quick Dates in SQL – Start of last week – End of last week

–Start of Last week
Select

dateadd(wk,-1,
(dateadd(yyyy, datepart(yyyy,
dateadd(weekday,1-datepart(weekday, getdate()),getdate()))-1900, 0)
+ dateadd(dy, datepart(dy,
dateadd(weekday,1-datepart(weekday, getdate()),getdate()))-1,0))
)

— End of last week

Select
dateadd(day, DateDiff(day, 0,

dateadd(wk,-1,dateadd(yyyy, datepart(yyyy,
dateadd(weekday,7-datepart(weekday, getdate()),getdate()))-1900, 0)
+ dateadd(ms, -3,
dateadd(dy, datepart(dy,
dateadd(weekday,7-datepart(weekday, getdate()),getdate())),0) ))
), 0)

Leave a Reply