Depending on the number of days you want to add as a maximum, you could just check for the day in a while loop and add another day via AddDays
as long as the current day of the week of expectedEndDate
falls on a weekend. Maybe something like this:
DateTime startDate = DateTime.Now
int durationDays = 2
DateTime expectedEndDate = startDate.AddDays(durationDays)
while( expectedEndDate.DayOfWeek == DayOfWeek.Saturday ||
expectedEndDate.DayOfWeek == DayOfWeek.Sunday )
{
expectedEndDate.AddDays( 1 );
}
If you need a more flexible solution for larger date differences covering multiple weekends, the linked solution from another post is for you (I was trying to keep it simple :-)).