Your question can be split into two questions:
- How to calculate holidays?
- How to calculate the number of holidays between the two given ranges?
The first question has many answers. You could enter them in a data base, download from a website, look for a C# class that calculates the holidays for your culture / environment (there are many!)
Then, you have to iterate through the days from start to end date. This can be done pretty easily:
DateTime startTime = new DateTime(2011, 4, 1);
DateTime endTime = new DateTime(2012, 4, 1);
int numberOfHolidays;
for (DateTime currentDate = startTime; currentDate <= endTime currentDate = currentDate.AddDays(1)) {
if (isHoliday(currentDate) || isWeekendDay(currentDate))
numberOfHolidays++;
}
You'll have to implement the methods isHoliday
and isWeekendDay
by your own, see the answer to the first question part.