Calculate Number of Days Between Two Dates using Python

datetime object and subtraction operator

from datetime import datetime

dateFormat = '%Y-%m-%d'
startDate = datetime.strptime('2020-11-08', dateFormat)
endDate = datetime.strptime('2020-11-10', dateFormat)

diff = endDate - startDate
numberOfDays = diff.days

print(numberOfDays)

Leave a Comment

Cancel reply

Your email address will not be published.