views:

80

answers:

1

In this other question it shows how to get all days of a month. I need the same thing, but I only want to list days of week (I want to exclude weekends).

How can I get a list of days of a month excluding weekends?

+11  A: 

Well, how about:

public static List<DateTime> GetDates(int year, int month)
{
   return Enumerable.Range(1, DateTime.DaysInMonth(year, month))
                    .Select(day => new DateTime(year, month, day))
                    .Where(dt => dt.DayOfWeek != DayOfWeek.Sunday &&
                                 dt.DayOfWeek != DayOfWeek.Saturday)
                    .ToList();
}
Jon Skeet
Was going to post the same myself, so you get my vote :)
Øyvind Bråthen
I missed that property. Thanks.
BrunoLM