Possible Duplicate:
how to get the days for particular month and year
Given the following method:
GetDaysPerMonth(string monthName, string year);
And the values "1" and "2010", how can I return the number of days within the specified month?
Possible Duplicate:
how to get the days for particular month and year
Given the following method:
GetDaysPerMonth(string monthName, string year);
And the values "1" and "2010", how can I return the number of days within the specified month?
How about using DateTime.DaysInMonth?
System.DateTime.DaysInMonth(year, month)
As an aside though, and possibly opening myself up to be shouted at, couldn't you just have tried typing "get days in month" into Google?
Note that the Calendar
class accepts month numbers, not month names, because month names are vary in different languages.
You simply want the System.DateTime.DaysInMonth
static method.
Example:
var daysInMonth = DateTime.DaysInMonth(2010, 7) // = 31
If you're given the year and month as strings, just call int.Parse
to get the value as a number.