0

How to calculate the difference days between two dates by using import date from datetime?(the dates must be input by user).

8th Apr 2017, 7:19 PM
Chilllittle
Chilllittle - avatar
4 Answers
+ 2
You can specify your date format which you prefer and use my code : https://code.sololearn.com/c790S6VkZTs7/?ref=app
8th Apr 2017, 7:38 PM
Shraddha
Shraddha - avatar
0
okayšŸ‘ŒšŸ»thank you so much
8th Apr 2017, 7:44 PM
Chilllittle
Chilllittle - avatar
22nd May 2021, 3:30 PM
Lovely
Lovely - avatar
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/
28th Feb 2026, 9:46 AM
Kieran Daniel
Kieran Daniel - avatar