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?
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.
To filter weekdays or weekend days, you apply Excel's filter to your table (Data tab > Filter) and select either "Workday" or "Weekend".
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();
}
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