How do you convert a str to timedelta?
I am trying to compare 2 different times from two different sources. Very similar to this Compare two dates with datetime.timedelta
But that answer is super unclear
error:
not supported between instances of 'datetime.timedelta' and 'str'
When it reads this line of code:
elif elapsed_time > maxtime_heatac:
Even though I set them the same way.
start_time = central.localize(d)
and
currentt = current.localize(d)
How do I convert a str to timedelta so I can do my comparison?
if plant_warning_flag == 0:
d = datetime.fromtimestamp(0)
central = pytz.timezone('US/Central')
start_time = central.localize(d)
#start_time = dt.datetime.now("{dt.datetime.now(tz=dt.timezone.utc):%H:%M:%S}")
plant_warning_flag = 1
#print("start_time ", start_time)
current = pytz.timezone('US/Central')
currentt = current.localize(d)
elapsed_time = currentt - start_time
print("current ", current, "start_time ", start_time)
print("\nelapsed_time: ", elapsed_time, "maxtime_heatac: ", maxtime_heatac)
elif elapsed_time > maxtime_heatac:
payload = {'on1':'4000'}
session = requests.Session()
session.post(acserver_url,headers=headers,data=payload)
The output of the format is ideal for me
elapsed_time: 0:00:00 maxtime_heatac: 00:00:30
So I don't want to reformat it, just compare.
Attempt update:
I tried
elapsed_time = datetime.strptime(elapsedtmp_time, '%H-%M-%S')
But I get this error
TypeError: strptime() argument 1 must be str, not datetime.timedelta
and I cannot get past that one.