Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created November 5, 2021 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elijah-trillionz/6d29243b6b7b9b8173018b2a377a9c9b to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/6d29243b6b7b9b8173018b2a377a9c9b to your computer and use it in GitHub Desktop.
calculate number of days between two dates
# Write a Python program to calculate number of days between two dates.
# (2014, 7, 2), (2014, 7, 11)
import datetime as date
def num_of_days(date_one, date_two):
try:
(year, month, day) = date_one
new_date = date.datetime(year, month, day).timestamp()
(year2, month2, day2) = date_two
new_date_two = date.datetime(year2, month2, day2).timestamp()
return int((new_date_two - new_date) / 86400)
except ValueError:
return 'Date is out of range, ensure your dates are rightly right'
days = num_of_days((2021, 11, 5), (2021, 12, 32))
print(days)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment