Friday, June 17, 2011

Find Number of Days in specific month

Recently I encountered the situation to find the number of days in specific month of the given year.In ASP.NET 3.5 comes up with built-in method called "DaysInMonth".This method takes two parameter as Year and Month.
If you want to find out the number of days for "January",then pass the value 1 for Month parameter.
int numberOfDays = DateTime.DaysInMonth(Convert.ToInt32(YearList.SelectedItem.Value), Convert.ToInt32(MonthList.SelectedItem.Value))