Calculate Number of Weeks Between Two Dates using Python

datetime object and subtraction operator

from datetime import datetime

dateFormat = '%Y-%m-%d'
startDate = datetime.strptime('2022-06-01', dateFormat)
endDate = datetime.strptime('2022-06-10', dateFormat)

diff = endDate - startDate
numberOfWeeks = diff.days // 7

print(numberOfWeeks)

Leave a Comment

Cancel reply

Your email address will not be published.