/ Published in: C#
A quick search on the internet reveals all kinds of ways you can calculate with business days. I think is the most simple and efficient. In this example add day of week and weeks separately. The loop is never iterated more then 4 times regardless of the number of days being added.
Comments
Subscribe to comments
You need to login to post a comment.

You can simplify this by not using nWeekDay and just using nDays. I created an extension method:
There is a bug in comment from MLaritz, at least when I change the method to be non extension. Fix is to assign the result of date.AddDays back in the date variable.
Here is my solution (unit tested): /// /// Add or remove some business days to a date time. /// /// /// /// public static DateTime AddBusinessDays(DateTime date, int days) { int direction = (days < 0) ? -1 : 1;
There is a bug in comment from MLaritz, at least when I change the method to be non extension. Fix is to assign the result of date.AddDays back in the date variable.
Here is my solution (unit tested): /// /// Add or remove some business days to a date time. /// /// /// /// public static DateTime AddBusinessDays(DateTime date, int days) { int direction = (days < 0) ? -1 : 1;