Technical Article

Number of days for a given month

,

Use this function to get the number of days in a given month.

Mohit Nayyar
MCP (.Net), MCSD, MCDBA

create function GetMonths (@Month smallint, @Year int)
returns smallint
as
begin
return(DAY(dateadd(dd,-1,DATEADD(m,1,cast(@Year as varchar(4)) + '-' + cast(@Month as varchar(2)) + '-01'))))
end

select DatabaseName.dbo.GetMonths (2,2002)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating