1

I need a way to find out if current time is in range of time window using time strings. So for example start time would be "0:00" and end time would be "3:15".

I came across this solution, How to check if the current time is in range in python?, and it's great but it doesn't use time strings. Is there anything in python that I can pass two time strings to and then check if something is between them? Any other suggestions?

Thanks.

Community
  • 1
  • 1
Pybeh
  • 13
  • 5
  • `time.strptime` is your friend, and some other converstions to get it to a `time.time()` format so you can do `if start < time.time() > end` logic. – Torxed Dec 22 '15 at 17:41
  • related: [python time range validator](http://stackoverflow.com/q/28526012/4279) – jfs Dec 22 '15 at 20:56

2 Answers2

0

This is a useful method of the time module: https://docs.python.org/2/library/time.html#time.strptime

Here is an example of it's usage:

import time
new_time = time.strptime("0:00", "%H:%M")
other_time = time.strptime("3:15", "%H%M")

print(new_time > other_time)
print(other_time > new_time)
abe
  • 504
  • 4
  • 13
0

Not really sure which version of Python you're using so I worked it up in python3.

import time

old_time = time.strptime('01:00', '%H:%M')
new_time = time.strptime('06:00', '%H:%M')

print(old_time)
print(new_time)

if old_time > new_time:
    print('old time is old')
else:
    print('new is cool')
Logan
  • 439
  • 4
  • 10