Read time and date from a text file

huisky huisky at
Wed Nov 24 16:02:16 CET 2010

On Nov 24, 2:45 pm, Peter Otten <__pete... at> wrote:
> huisky wrote:
> > I see the problem of year. But the question is the source file does
> > NOT provide the year information.
> > for instance if i have one record as ['Dec','6','21:01:17'], and the
> > other as ['Jan','6','21:01:17']
> > these two records may be in different year. Will it be a problem to
> > use the 'datetime' do the time difference calculation?
> You have a problem that is independent of Python. You have to guess the
> correct year to get the correct time interval. One approach would be to use
> the year from the file's timestamp, then calculate the differences, and
> whenever you get a negative interval add one year to the end date.
> This will still result in rare ValueErrors (Feb 29 in non-leapyears) and
> some silent miscalculations; I fear you'll have to live with that.
> Peter

I see, what i'm doing is only for personal usage. should be no problem
at all.
thanks a lot, Peter!

More information about the Python-list mailing list