I’m trying to create a generator function to iterate over business days (weekdays), skipping weekends (and holidays would be nice too!). So far, I only have a function that simply iterates over days:
def daterange(startDate, endDate):
for i in xrange(int((endDate - startDate).days)):
yield startDate + timedelta(i)
I’m struggling to figure out a clean, efficient, and pythonic way to make the generator skip over weekends and holidays. Thanks in advance!
I would strong recommend using the dateutil library for such tasks. A basic (not ignoring holidays) iterator over business days then simply is: