Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

date countdown not working as intended. time keeps printing

I have made a script to show the difference between today’s date and a date you put in and ended it with the print function and an f string.

from datetime import datetime

today = datetime.today()
print("Please enter the date you want to find out how many days until below: ")
year = int(input("What year? "))
month = int(input("What month? "))
day = int(input("What day? "))


date2 = datetime(year, month, day)

difference = date2 - today

print(f"There are only {difference.days+1} days left until {date2} from {today}")

it prints the correct data however it shows the time aswell.
so it shows this as an example:
"There are only 96 days left until 2023-02-23 00:00:00 from 2022-11-19 00:14:18.003365"

how do I remove the time?
also if there are any other suggestions on improving this I’m all ears.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use date for this calculation.

from datetime import date

today = date.today()
print("Please enter the date you want to find out how many days until below: ")
year = int(input("What year? "))
month = int(input("What month? "))
day = int(input("What day? "))


date2 = date(year, month, day)

difference = date2 - today

print(f"There are only {difference.days+1} days left until {date2} from {today}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading