Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
DECLARE @dt as datetime
set @dt='12/30/2004' -- Any old date
-- Gives first day of year
select dateadd(dy, -datepart(dy, @dt)+1, @dt)
-- Gives first day of next year
select dateadd(year, 1, dateadd(dy, -datepart(dy, @dt)+1, @dt))
-- Gives last day of year
select dateadd(dy, -1, dateadd(year, 1, dateadd(dy, -datepart(dy, @dt)+1, @dt)))
DECLARE @dt as datetime
-- Loop through 1 year
set @dt='1/1/2004'
while datepart(year, @dt)=2004
begin
SELECT
datepart(wk, @dt) as WEEK_NUM,
NUM_DAYS_IN_WEEK =
CASE
WHEN datepart(wk, @dt)=1
THEN 7-datepart(dw, dateadd(dy, -datepart(dy, @dt)+1, @dt))+1
WHEN datepart(wk, @dt)=53
THEN datepart(dw, dateadd(dy, -1, dateadd(year, 1, dateadd(dy, -datepart(dy, @dt)+1, @dt))))
ELSE 7
END
set @dt=dateadd(dd, 7, @dt)
end