public static DateTime AddWeekdays( DateTime start, int days )
{
if ( start.DayOfWeek == DayOfWeek.Saturday || start.DayOfWeek ==
DayOfWeek.Sunday ) {
throw new ArgumentException( "start must be a weekday" );
}
int remainder = days % 5;
int weekendDays = ( days / 5 ) * 2;
DateTime end = start.AddDays( remainder );
if ( end.DayOfWeek == DayOfWeek.Saturday ) {
// add two days for landing on saturday
end = end.AddDays( 2 );
}
else if ( end.DayOfWeek < start.DayOfWeek ) {
// add two days for rounding the weekend
end = end.AddDays( 2 );
}
// add the remaining days
return end.AddDays( days + weekendDays - remainder );
}
"Darin" <dvan...@edgewater.com> wrote in message
news:58dd01c1f2c1$c93a36d0$2ae2...@hosting.microsoft.com...
> I need to add x amount of weekdays to today. An example
> would be if today is Thursday and the user enters a 4 I
> need to add 4 weekdays to today which would be Tuesday.
>
> I searched on DateTime and weekdays in Help and this
> newsgroup but didn't find anything helpful.
>
> Any suggestions on how to accomplish this?
>
> Thanks,
> Darin