0

I am trying to check if the current time if between two predermined times and that the day is Monday, Tuesday, Wednesday or Thursday. Something like:

if day = monday, tuesday, wednesday or thursday
   if current_time > 6:00 PM and current_time < 6:15 PM
      then do something

Here is what I have so far, the only bit left is setting the two times I want to check between:

weekday = datetime.datetime.today().weekday()
hour = datetime.datetime.time(datetime.datetime.now())

if weekday < 5:
    if hour
JaAnTr
  • 896
  • 3
  • 16
  • 28

1 Answers1

0

You may use datetime.weekday() method and attributes: datetime.hour and datetime.minute.

now = datetime.datetime.now()
if now.weekday() < 5 and now.hour == 18 and 0 <= now.minute <= 15:
    do_something()
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
  • use `now.weekday() < calendar.FRIDAY` otherwise Friday (`==4`) is included. To support start/end time with different hours, see [`in_between()`](http://stackoverflow.com/a/33681543/4279) – jfs Feb 08 '16 at 11:01