How to compare to time strings?

Mark McEahern marklists at mceahern.com
Sat Jan 19 17:10:03 EST 2002


Short answer:  Use mx.DateTime from egenix:

  http://www.egenix.com/files/python/eGenix-mx-Extensions.html#mxBASE

Here's sample code, once you've installed that:

$ python
>>> s1 = "Mon, 31 Dec 2001 15"
>>> import mx.DateTime
>>> d1 = mx.DateTime.DateFrom(s1)
>>> print d1
2001-12-31 00:00:00.00
>>> s2 = "Sat, 19 Jan 2002 21"
>>> d2 = mx.DateTime.DateFrom(s2)
>>> print (d2 > d1)
1

// mark




More information about the Python-list mailing list