Wednesday, August 06, 2014

Calculating the number of working days using Python

At times, we have a requirement to calculate the number of weekdays / working days between two dates.
Here's how you do it using Python:

But the above method involves usage of loops.
A more optimized way of doing it would be:

In our project, we faced a requirement where given a start date, we had to calculate end date as start date + x working days.
Using the above logic, we can do:

If you have a list of holidays to exclude, you could then do: