This is an example.
Notes:
- It uses datetime.datetime.now() to get time including hours, minutes and seconds
- It uses datetime.datetime(...) instead of datetime.date(...), because the latter is not compareable with datetime.datetime.now() (datetime and date are not compareable, because the latter lacks specific timing information
- It uses https://stackoverflow.com/a/539360/8575607 to get minutes and hours from timedelta
- It uses print(..., end="\r") to not always create a new line, and print("\n...") to force a new line
import datetime
import time
current_date = datetime.datetime.now() # Now gives current minutes, seconds...
print('Today is: ' + str(current_date))
def getdate():
year = int(input('Enter a year: '))
month = int(input('Enter a month: '))
day = int(input('Enter a day: '))
date_user = datetime.datetime(year, month, day, 0, 0, 0) # Midnight
return date_user
date_user = getdate()
while date_user > current_date:
current_date = datetime.datetime.now()
diff = date_user - current_date
# Using https://stackoverflow.com/a/539360/8575607
s = diff.seconds
# hours
hours = s // 3600
# remaining seconds
s = s - (hours * 3600)
# minutes
minutes = s // 60
# remaining seconds
seconds = s - (minutes * 60)
print("{}day(s) {}h {}min(s) {}sec(s) left".format(diff.days, hours, minutes, seconds), end='\r')
time.sleep(1)
print('\nThis is past bro, wake up!')
I would suggest you to better specify your question the next time. Examples would be "How do I print out a time delta the following way?" or "How do I execute a line of code every second until a goal is reached?" You went for asking about the bigger picture, which often does not give you that useful answers ^^