Skip to content

Instantly share code, notes, and snippets.

@giorgiberia
Last active October 16, 2020 11:53
Show Gist options
  • Save giorgiberia/a1d9e8ea6072bcb6922be2acb5456c21 to your computer and use it in GitHub Desktop.
Save giorgiberia/a1d9e8ea6072bcb6922be2acb5456c21 to your computer and use it in GitHub Desktop.
datetime python useful
import datetime as dt
# 2020-10-14 12:00:00
first_date = dt.datetime.strptime(first_date, '%Y-%m-%d %H:%M:%S')
# 2020-10-16 12:05:05
second_date = dt.datetime.strptime(second_date, '%Y-%m-%d %H:%M:%S')
diff = second_date - first_date
hours = diff.days * 24 + diff.seconds // 3600
minutes = (diff.seconds % 3600) // 60
seconds = diff.seconds % 60
#48 5 5
print(hours, minutes, seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment