Code logic to calculate the number of business dates between two dates

The code snippet, shown below will help you to calculate the number of business days between two dates in C#.

public int calc(DateTime today, DateTime delivery)

//day in which order is placed and expected delivery date are passed as parameters
{
int Bday = 0;
DateTime businessDay;
for (businessDay = today; businessDay <= delivery; businessDay=businessDay.AddDays(1))

//iterate from the current date to expected delivery date
{
if (businessDay.DayOfWeek.ToString() != “Saturday” && businessDay.DayOfWeek.ToString() != “Sunday”)
{
Bday++;

// increments the days if the present day is not a Saturday or a Sunday
}
}
return Bday;    //returns the number of business days starting from today
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s