Thursday, March 11, 2010

AddWeekDays Extension Method

Ever need to add week days to a date?  Use this extension method…

 public static DateTime AddWeekDays(this DateTime startDate, int days)
{
DateTime d = startDate;
int i = 1;
while (days >= i)
{
d = d.AddDays(1);
if (d.DayOfWeek != DayOfWeek.Saturday & d.DayOfWeek != DayOfWeek.Sunday)
i++;
}
return d;
}

No comments:

Post a Comment