Skip to content

Instantly share code, notes, and snippets.

@miohtama
Created May 28, 2012 23:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miohtama/2821647 to your computer and use it in GitHub Desktop.
Save miohtama/2821647 to your computer and use it in GitHub Desktop.
Sorted datetime objects with Python
# 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)
@Prasannasai3698
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment