Created
May 28, 2012 23:30
-
-
Save miohtama/2821647 to your computer and use it in GitHub Desktop.
Sorted datetime objects with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The trick is to pass timedelta object as a sort key and not to use cmp() function | |
import datetime | |
def date_key(a): | |
""" | |
a: date as string | |
""" | |
a = datetime.datetime.strptime(a, '%d.%m.%Y').date() | |
return a | |
sorted_dates = sorted(sorted_dates, key=date_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to do it ?
The time stamp is like: <2020-06-06T06:31:48.034549Z>
<2020-06-06T06:31:48.034821Z>
<2020-06-06T06:31:48.034854Z>
<2020-06-06T06:31:48.221945Z>