I have a string of a timespan like this:
timespan = '08.00-14:00'
I want to know if this timespan is at least n hours, for example 2 hours:
if timespan >= 2:
do something
I have a string of a timespan like this:
timespan = '08.00-14:00'
I want to know if this timespan is at least n hours, for example 2 hours:
if timespan >= 2:
do something
Edit: You can try something like
from datetime import datetime, timedelta
timespan = '23.00-01:00'
start_time, end_time = timespan.split('-')
start_time = datetime.strptime(start_time, '%H.%M')
end_time = datetime.strptime(end_time, '%H:%M')
if end_time <= start_time:
# end_time is on the next day, add 1 day to end_time
end_time += timedelta(days=1)
duration = end_time - start_time
if duration >= timedelta(hours=2):
print("The duration is at least 2 hours.")
else:
print("The duration is less than 2 hours.")