I\'m trying to find the cleanest/most pythonic way of evaluating if \"now\" is between two times; However; the Start/End times may, or may not, fall across a day boundary- f
To find out whether a given time (no date) is in between given start, end times (the end is not included):
def in_between(now, start, end):
if start <= end:
return start <= now < end
else: # over midnight e.g., 23:30-04:15
return start <= now or now < end
Example:
from datetime import datetime, time
print("night" if in_between(datetime.now().time(), time(23), time(4)) else "day")