I made a countdown function (which works just fine) that returns the time remaining as a string. I'm using the strptime
and strftime
functions to sort of parse the data so I could have a variable for how many days, hours, minutes and seconds that are remaining. My code gives me an error as soon as the days exceed 31 (because of the month). Any ideas how I can fix it?
from datetime import datetime, date
a = "31 days, 23:52:51"
b = "32 days, 23:52:51"
d = datetime.strptime(b, "%d days, %H:%M:%S")
t1 = d.strftime("%d")
t2 = d.strftime("%H")
t3 = d.strftime("%M")
t4 = d.strftime("%S")
print(t1)
print(t2)
print(t3)
print(t4)