Assuming your start date is a weekday, just add 7 days to it. The calculation for an arbitrary number of days would be as follows:
DateTime StartDate = new DateTime(2015, 9, 2);
DateTime EndDate = StartDate.AddDays(duration/5*7+duration%5);
Assuming we have an array of businessHolidays
, we could account for those as well:
for( var index = 0; index < businessHolidays.length; index++) {
var holiday = businessHolidays[index];
if (holiday.Date >= StartDate.Date && holiday.Date <= EndDate.Date) {
EndDate.AddDays(1);
}
}
Finally, we check the resulting date to see if it falls on a weekend. This is necessary if the start date was a weekend or we pushed the date due to a holiday.
if ( EndDate.DayOfWeek == DayOfWeek.Saturday ) {
EndDate.AddDays(2);
} else if ( EndDate.DayOfWeek == DayOfWeek.Sunday ) {
EndDate.AddDays(1);
}