Calculate Weeks Start & end Date for current date


DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime



--get number of a current day (1-Monday, 2-Tuesday... 7-Sunday)
SET @TodayDayOfWeek = datepart(dw, GetDate())
print @TodayDayOfWeek
--get the last day of the previous week (last Sunday)
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
print @EndOfPrevWeek


--get the first day of the previous week (the Monday before last)
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
print @StartOfPrevWeek




--get the last day of the previous week (last Sunday)
print DATEADD(dd, 7-@TodayDayOfWeek, GetDate())



--get the first day of the previous week (the Monday before last)
print DATEADD(dd, -(@TodayDayOfWeek-1), GetDate())

Comments

Popular posts from this blog

GROUP BY, CUBE, ROLLUP and SQL SERVER 2005

How to get content of Ckeditor & Fckeditor using Javascript

How to Fix Error- Sys.WebForms.PageRequestManagerTimeoutException - The server request timed out