date countdown not working as intended. time keeps printing

Question:

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.

Asked By: MoRayhxn

||

Answers:

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}")
Answered By: Chris Charley
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.