How do I calculate how many days there are between two dates?

Asked 2 years ago, Updated 2 years ago, 130 views

How do I calculate how many days there are between two dates?

For example, I don't know how to create a Python code to find out how many days there are between '8/18/2008' and '9/26/2008'

datetime python

2022-09-22 22:12

1 Answers

You can just create and subtract the date object.

from datetime import date

d0 = date (2008, 8, 18) #dateobject1
d1 = date (2008, 9, 26) #dateobject2
delta = d0 - d1 # Subtract
print delta.days #calculated by date


2022-09-22 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.