[Tutor] Finding and Inserting missing dates in a date range.

Kent Johnson kent37 at tds.net
Fri Oct 9 22:43:53 CEST 2009

On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami <digitalman66 at gmail.com> wrote:
> If i have a list of dates:
> date_list =
> ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> How do I find the missing dates in the range of dates and insert them into
> the list so I get?
> date_list =
> ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']

I would do something like the following using datetime.datetime and
- convert each list item to a datetime object using datetime.strptime()
- find the min and max datetimes in the list (use min() and max()
- create a new list by incrementing the min date by timedelta(days=1)
until it hits the max date
- convert the new list to strings using datetime.strftime()


More information about the Tutor mailing list