0
How to calculate the difference days between two dates by using import date from datetimeļ¼ļ¼the dates must be input by userļ¼.
4 Answers
+ 2
You can specify your date format which you prefer and use my code :
https://code.sololearn.com/c790S6VkZTs7/?ref=app
0
okayšš»thank you so much
0
You can see this
https://code.sololearn.com/c67p6r62E7u5/?ref=app
0
You can calculate the difference between two user-input dates using datetime like this:
from datetime import datetime
date1 = input("Enter first date (YYYY-MM-DD): ")
date2 = input("Enter second date (YYYY-MM-DD): ")
d1 = datetime.strptime(date1, "%Y-%m-%d")
d2 = datetime.strptime(date2, "%Y-%m-%d")
difference = abs((d2 - d1).days)
print("Difference in days:", difference)
This converts the input strings into date objects and then subtracts them to get the total number of days.
If someone just needs a quick way to calculate date or age differences without coding, there are simple online tools available as well, for example: https://myagecalculate.com/



