public static DateTime AddWorkdays(this DateTime originalDate, double workDays) { DateTime tmpDate = originalDate; while (workDays > 0) { tmpDate = tmpDate.AddDays(1); if (tmpDate.DayOfWeek < DayOfWeek.Saturday && tmpDate.DayOfWeek > DayOfWeek.Sunday && !DateTimeExtension.IsHoliday(tmpDate)) { workDays--; } } return(tmpDate); }
// give days difference exclude start and end Date public static double TotalDaysLeftInMinutes(DateTime?startDate, DateTime?endDate, Boolean excludeWeekends) { startDate = startDate.Value.AddDays(1); double count = 0; for (DateTime?index = startDate; index.Value.Date < endDate.Value.Date; index = index.Value.AddDays(1)) { if (excludeWeekends && index.Value.DayOfWeek != DayOfWeek.Sunday && index.Value.DayOfWeek != DayOfWeek.Saturday) { bool excluded = false; if (DateTimeExtension.IsHoliday(index)) { excluded = true; } if (!excluded) { count++; } } } return(count * 480); }