[Tutor] Finding and Inserting missing dates in a date range.
RĂ¼diger Wolf
rudiger.wolf at throughputfocus.com
Sat Oct 10 00:11:28 CEST 2009
Ah! but are we sure that the max and min dates are actually in the list?
If there are 'missing dates' it might just be possible that it is the
max or min date that is missing.
On Fri, 09 Oct 2009 16:43 -0400, "Kent Johnson" <kent37 at tds.net> wrote:
> 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
> datetime.timedelta:
> - 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()
>
> Kent
More information about the Tutor
mailing list