How can I get the number of weekdays between two given dates without just iterating through the dates between and counting the weekdays?
Seems fairly straightforward but I can’t seem to find a conclusive correct answer that abides by the following:
- The total should be inclusive, so GetNumberOfWeekdays(new DateTime(2009,11,30), new DateTime(2009,12,4)) should equal 5, that’s Monday to Friday.
- Should allow for leap days
- does NOT just iterate through all the dates between whilst counting the weekdays.
I’ve found a similar question with an answer that comes close but is not correct
From this link:
Tests (each test returns 5):