How do I compare an object datetime.datetime.now().time() with an integer like 12?
I need to make an if condition, which checks whether the time of day is before 12PM or after 12PM and take corresponding action.
Answer
Simple: you don't. You create a datetime object to compare instead:
import datetime
a = datetime.datetime.now().time()
b = datetime.time(12, 00, 00, 000000)
if a < b:
print("Do x here")
else:
print("Do y here")
No comments:
Post a Comment