[Tutor] iterate over daterange
kent37 at tds.net
Sat Jan 7 15:15:54 CET 2006
> I have a startdate and an enddate and I want to iterate over all days
> in between the two
> .... there doesn't seem to be a range function for dates?!?
> i.e. currently I am going through integers with something like this:
> startdate = datetime.date(2006,1,1)
> enddate = datetime.date(2006,10,19)
> for i in range((enddate-startdate).days + 1):
> currentdate = startdate + datetime.timedelta(days=i)
> this seems so 'unpythonic', there surely must be a better way, no?
currentdate = datetime.date(2006,1,1)
enddate = datetime.date(2006,1,19)
while currentdate <= enddate:
currentdate += datetime.timedelta(days=1)
seems a little better to me.
Gustavo Niemeyer's dateutil package includes very flexible recurrence
rules - see
More information about the Tutor