Is it reliable to compare two isoformat datetime strings?

Viewed 14562

I need to find out which of two isoformatted datetime strings is the latest.

By now, I convert them using datetime.strptime method. Then I compare two datetime objects. Then I call isoformat of the greatest datetime object in order to pass it as a get parameter.

So I'm wondering if it is reliable to find out the greatest isoformatted string without doing converstion from str to datetime.

It seems to work:

>>> from datetime import datetime as dt
>>> s1 = '2013-12-25T19:20:41.391393'
>>> s2 = '2013-12-25T19:20:41.391394'
>>> s1 > s2
False
>>> pattern = '%Y-%m-%dT%H:%M:%S.%f'
>>> dt.strptime(s1, pattern) > dt.strptime(s2, pattern)
False
2 Answers
Related