I have two dates: current and new year.
It is clear that through the DateTime
in Python 3
you can deduct these dates and get a new one, but how can you calculate the amount of time to the new year in seconds, days, minutes , hours, etc.
Example:
to the new year: 60 days 22 hours 45 minutes 12 seconds.
Answer 1, Authority 100%
Why not see what happens if subtract these dates .
And it turns out the object class Timedelta, which contains what you need
now = datetime.datetime.today ()
NY = DateTime.dateTime (2020,1,1)
D = NY-NOW # STR (D) '83 Days, 2: 43: 10.517807 '
MM, SS = DIVMOD (D.Seconds, 60)
HH, MM = Divmod (mm, 60)
Print ('To New Year: {} days {} hour {} min {} sec.'. Format (D.days, HH, MM, SS))
# New Year: 83 days 2 hours 43 min 10 seconds.