tags:

views:

92

answers:

3

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?

+5  A: 

Calendar.GetDaysInMonth

Note that the Calendar class accepts month numbers, not month names, because month names are vary in different languages.

Tim Robinson
+2  A: 

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.

Noldorin
@anishmarokey: Don't be dense. Give the OP more credit than that.
Noldorin
@Anish: i need to get output like mm/dd : 1/1,1/2,1/3,1/4
+7  A: 

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?

Rob Levine
Shaihi
The OP didn't specify the calander system they're using, so Tim's answer is better.
Skizz
@Skizz - yes. There is an implicit assumption in mine that user wants the days in the month for the currently set calendar, which may not actually be true.
Rob Levine