Search

C#: Get num of days in month

DateTime.DaysInMonth(int year, int month);
 
     //or
 
static int GetDaysInMonth(int year, int month)
{
DateTime dt1 = new DateTime(year, month, 1);
DateTime dt2 = dt1.AddMonths(1);
TimeSpan ts = dt2 - dt1;
return (int)ts.TotalDays;
}