Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if it's Monday to Friday and the time is between 10 AM to 3 PM?

Tags:

In python how do I check if its a weekday (Monday - Friday) and the time is between 10 AM to 3 PM?

like image 290
Vishal Avatar asked Dec 15 '09 12:12

Vishal


People also ask

How do you check if time is greater than or less than a specific time in python?

now(). time() print(time_in_range(start, end, current)) # True (if you're not a night owl) ;) The code returns True if you run it between (hh:mm:ss) 00:00:00 and 23:55:00 on your computer. Only if you run it between 23:55:00 and 23:59:59 it returns False .

How do you check if a date is weekday in Python?

Check if a date is a weekday or weekend We can use the weekday() method of a datetime. date object to determine if the given date is a weekday or weekend. Note: The weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, the date(2022, 05, 02) is a Monday.

How do you check if time is within a certain range in Python?

Use the datetime. time class for start , end , and x . if start=today[10:00], end=tomorrow[10:00], and x = 11:00 then start <= x <= end = False !!! @PauloScardine: You have to choose how to interpret it: whether [10:00, 10:00] has length 0 or 24 hours.


2 Answers

>>> import datetime >>> d = datetime.datetime.now()  # => datetime.datetime(2009, 12, 15, 13, 50, 35, 833175)  # check if weekday is 1..5 >>> d.isoweekday() in range(1, 6) True  # check if hour is 10..15 >>> d.hour in range(10, 15) True  # check if minute is 30 >>> d.minute==30 False 
like image 140
miku Avatar answered Sep 21 '22 15:09

miku


>>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2009, 12, 15, 12, 45, 33, 781000) >>> now.isoweekday() 2        # Tuesday 

time between 10 a.m. and 3 p.m. is right there as well

like image 32
SilentGhost Avatar answered Sep 23 '22 15:09

SilentGhost