public static int GetNonWorkdays(DateTime from, DateTime to)
{
DateTime dtBegin = from;
DateTime dtEnd = to;
int dayCount = 0;
//while the End date is not reached
while (dtEnd.CompareTo(dtBegin) > 0)
{
//check if the day is not a weekend day
if ((dtBegin.DayOfWeek == DayOfWeek.Saturday) || (dtBegin.DayOfWeek == DayOfWeek.Sunday))
dayCount++;
//go to next day
dtBegin = dtBegin.AddDays(1);
}
return dayCount;
}
