[SOLVED] How to get the data only on working hours


Is there a way to select or query the data only on working hours?

id description datetime
1 Alarm Activated 2022-01-02 14:00:00
2 Alarm Deactivated 2022-01-02 15:00:00
3 Alarm Activated 2022-01-03 18:00:00
.. Alarm Activated 2022-01-31 11:00:00

I’d like to get the number of the alarm activated on or during working hours from mon-fri 8am to 5pm.

I tried to use the between date but no luck.


SELECT *        -- if you need to count them only - use SELECT COUNT(*)
FROM datatable
WHERE WEEKDAY(`datetime`) < 5                               -- test weekday
  AND TIME(`datetime`) BETWEEN '08:00:00' AND '17:00:00';   -- test hours

Answered By – Akina

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *