I have two dates as datetime.date
objects, what is the most Pythonic way to find a number of workdays between these two dates (including starting and excluding ending date)? For example:
from datetime import date, timedelta
d1 = date(2019, 3, 1)
d2 = date(2019, 5, 6)
# The difference between d2 and d1 is 46 workdays
Writting a loop comes to my mind:
workdays = 0
for i in range((d2 - d1).days):
if (d1 + timedelta(days=i)).isoweekday() <= 5:
workdays += 1
However, I think there is a simpler way to solve this problem.