Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
from datetime import datetime
for x in range(1,3):
my_string = str(input('Enter date(yyyy-mm-dd): '))
my_date = datetime.strptime(my_string, "%Y-%m-%d")
if x==1:
date1=my_date.date()
print("Date1",date1)
elif x==2:
date2=my_date.date()
print("Date2",date2)
else:
pass
result=date2-date1
difference=result
print(difference,"days")

What I have tried:

output :
Enter date(yyyy-mm-dd): 2010-2-2
Date1 2010-02-02
Enter date(yyyy-mm-dd): 2020-2-3
Date2 2020-02-03
3653 days, 0:00:00 days
output should be days, but here
0:00:00 days is executing how to clear it?
Posted
Updated 3-Jan-22 5:25am
Comments
0x01AA 3-Jan-22 11:24am    
This should do it: print(difference.days,"days")

1 solution

To print only the days without hh:mm:ss you can use this:
print(difference.days,"days")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900