Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

datetime weekdays

356 views
Skip to first unread message

Brad Quinn

unread,
May 6, 2002, 9:12:28 AM5/6/02
to
I tried posting this on Friday, but I guess the servers were down.

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


0 new messages