I have a method which passes two parameters Month and year
i will call this Method like this : MonthDates(January,2010)
public static string MonthDates(string MonthName,string YearName)
{
return days;
}
How to get the days for particular month and year?
do you mean the number of days in a month?
System.DateTime.DaysInMonth(int year, int month)
If you want all days as a collection of DateTime
:
public static IEnumerable<DateTime> daysInMonth(int year, int month)
{
DateTime day = new DateTime(year, month, 1);
while (day.Month == month)
{
yield return day;
day = day.AddDays(1);
}
}
The use is:
IEnumerable<DateTime> days = daysInMonth(2010, 07);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With