So the specification is following:
We need to calculate number of working days between two dates - it mean’s we need to calculate all days excluding Saturday and Sunday. If the function is running after 6:00 pm this working day need to be also excluded.
After some googling I’ve found this task could be resolved using rrule module. Be sure you have dateutil library installed to use this example.
1 2 3 4 5 6 7 8 9
Here byweekday parameter is a list of days of week we want to caculate, ti’s elements can be integers (Monday is 0, Tuesday is 1 etc) or rrule objects – rrule.MO, rrule.TU etc. Other usefull methods for date (e.g. full weeks) calculations could be found here.
Suppose we need to calculate days from 1-01-2013 until 28-07-2013. Our code will be:
1 2 3 4 5
The output will be: 142 (Calculate yourself if don’t trust me).