Technical Article

function to get the number of days in a month

,

This functin returns the number of days in a month, given the month and the year. It does this by adding 1 month to the first of the month, substract 1 day and get the day part of the result.

create function fn_NbDays ( @month int, @year int )
returns int
as
begin
return datepart(dd,dateadd(dd,-1,dateadd(mm,1,convert(datetime,right('0000'+convert(varchar(4),@year),4) + right('00'+convert(varchar(2),@month),2) + '01' ))))
end

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating