Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of week days in a month?

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?

like image 462
BrunoLM Avatar asked Oct 26 '10 10:10

BrunoLM


People also ask

How do I show days in a month in Excel?

Formula: Get Total Days in a Month We have EOMONTH which is covered within DAY. First, when you refer to a date and “0” in EOMONTH it returns the last date of that month. Here the date is on cell A2. Second, the DAY function returns the day from the last day returned by EOMONTH.

How do I filter weekdays in Excel?

To filter weekdays or weekend days, you apply Excel's filter to your table (Data tab > Filter) and select either "Workday" or "Weekend".


1 Answers

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();
}
like image 88
Jon Skeet Avatar answered Sep 19 '22 06:09

Jon Skeet