Get The Number Of Days In The Current Month

T-SQL code snippet to get the number of days in the current month.

declare @numberOfDaysInMonth int;
declare @theDate datetime
select @theDate = '02/02/2008'

set @numberOfDaysInMonth = DAY(DATEADD (m, 1, DATEADD (d, 1 - DAY(@theDate), @theDate)) - 1);

print @numberOfDaysInMonth

Leave a Reply