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

Glen Zangirolami digitalman66 at gmail.com
Sat Oct 10 00:15:37 CEST 2009


Thats for all the responses. I'm going to use Kents method. I'll let you
know what I work out.
Rudiger - I did think about that. Luckily I am generating the list with a
start datetime and end datetime so if those don't exist
in either end if the list I can insert them after I check the dates between.


On Fri, Oct 9, 2009 at 5:11 PM, Rüdiger Wolf <
rudiger.wolf at throughputfocus.com> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091009/b0711a4c/attachment-0001.htm>


More information about the Tutor mailing list