Last active
October 16, 2020 11:53
-
-
Save giorgiberia/a1d9e8ea6072bcb6922be2acb5456c21 to your computer and use it in GitHub Desktop.
datetime python useful
This file contains hidden or 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
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