datetime.iterdate

Robert Brewer fumanchu at amor.org
Sun Jul 11 21:04:29 EDT 2004


Anyone else tired of typing date-addition logic when iterating? It would
be nice if the datetime package had something like:

def iterdates(first, last):
    for day in range((last - first).days + 1):
        yield first + datetime.timedelta(day)

...notice the inclusive boundaries (i.e. last gets returned). This
simple construct would make ugly date loops a lot cleaner:

for day in datetime.iterdates(first_date, last_date):
   do_something_with(day)



Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list