sorting date-strings of form: Wed, 05 Jan 2000 10:07:02

Hans Nowak ivnowa at hvision.nl
Thu Dec 14 08:54:34 EST 2000


Jorn Verwey wrote:
> 
> Hello,
> 
> I have a document with a lot of sections which need to be ordered by date. The date is given in the
> format given in the subject: Wed, 05 Jan 2000 10:07:02. How would I go about? Being a novice I would
> rather not re-invent the wheel (it will end up square). I took notice of two packages which might
> help me (mxDateTime and normalDate), but it didn't seem straight forward. I welcome suggestions!
> TIA.

You can use the rfc822 module:

>>> import rfc822
>>> rfc822.parsedate('Wed, 05 Jan 2000 10:07:02')
(2000, 1, 5, 10, 7, 2, 0, 0, 0)

This returns a 9-tuple with time & date info. It can be used directly
for sorting. If necessary, the tuple could be processed further with the
time module.

HTH,

--Hans Nowak
Cheapo Vision Europe BV



More information about the Python-list mailing list