Wednesday, 18 September 2013

How to check in python if I'm in certain range of times of the day?

How to check in python if I'm in certain range of times of the day?

I want to check in python if the current time is between two endpoints
(say, 8:30 a.m. and 3:00 p.m.), irrespective of the actual date. As in, I
don't care what the full date is; just the hour. When I created datetime
objects using strptime to specify a time, it threw in a dummy date (I
think the year 1900?) which is not what I want. What's the easiest and
most pythonic way to accomplish this?
Extending a bit further, what I'd really like is something that will tell
me if it's between that range of hours, and that it's a weekday. Of course
I can just use 0 <= weekday() <= 4 to hack this, but there might be a
better way.

No comments:

Post a Comment