Tuesday, September 21, 2010

This Function is used to calculate the number of week days in given date range

///
/// This Function is used to calculate the number of week days in given date range
///

/// Number of Week Days
public int CalculateNumberOfWeekdays(String stdate, String etdate)
{
DateTime dtBegin = DateTime.Parse(stdate);
DateTime dtEnd = DateTime.Parse(etdate);

int dayCount = 0;

while (dtEnd.CompareTo(dtBegin) > 0)
{

//check if the day is not a weekend day
if ((dtBegin.DayOfWeek != DayOfWeek.Saturday) && (dtBegin.DayOfWeek != DayOfWeek.Sunday))
{
dayCount++;
}

//go to next day
dtBegin = dtBegin.AddDays(1);

}

return dayCount;
}

No comments:

Post a Comment