declare @month int, @year int, @date datetime
select @month = 2, @year = 2000
select @date = convert(varchar, @year) + right('0' + convert(varchar, @month), 2) + '01'
select datediff(d, @date, dateadd(m, 1, @date)) as "Number of Days"

-- This one determines the last day of the month.
-- Uses almost similar logic as the above statement.
select dateadd( d, -1 , dateadd( m , 1 , @date ) ) AS "Last Day Of Month"
This page was last updated on May 01, 2006 04:28 PM.