timothy.shawley (8/13/2012)
One issue - the Leap Day calculation is missing one constraint - February does not have 29 days in Centuries not divisible by 400, ie 2100 will be 28 days, but 2000 was 29 days.Otherwise the script looks like it works like a charm...
That's what I saw, but it can easily be corrected if you add two conditions to the CASE
set @TotalMonthDays = case when @currentMonth in (1,3,5,7,8,10,12) then 31
when @currentMonth in (4,6,9,11) then 30
when @currentMonth = 2 and @YearNo % 400 = 0 then 29
when @currentMonth = 2 and @YearNo % 100 = 0 then 28
when @currentMonth = 2 and @YearNo % 4 = 0 then 29
when @currentMonth = 2 and @YearNo % 4 > 0 then 28