Ad

How To Get The Data Only On Working Hours

- 1 answer

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

iddescriptiondatetime
1Alarm Activated2022-01-02 14:00:00
2Alarm Deactivated2022-01-02 15:00:00
3Alarm Activated2022-01-03 18:00:00
..Alarm Activated2022-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.

Ad

Answer

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
Ad
source: stackoverflow.com
Ad