MS SQL Tips & Tricks

How to find a number of days in a month

To find the number of days in a month, the easiest way will be finding its last day date and just get the DAY part. As bellow:

declare @cDateTime datetime;
set @cDateTime = '2009-02-04'

select 	day(dateadd(d,-1,dateadd( month, 
			datediff( month, 0, @cDateTime )+1,0 
		))) as DaysInMonth

Learn more tricks

Add Comment