IGGt
IGGt

Reputation: 2779

MySQL Scheduled Events - Option to run DAILY, BETWEEN x and Y?

Using a MySQL (5.5.x) Scheduled Event, is there a way to set it to run DAILY, every 1 HOUR between 8AM and 6PM. I have been through the documentation, but can't see anything that stands out so I think the answer is probably no, but wondered if anybody else knew otherwise?

There appears to options to run Daily (EVERY 1 DAY), or HOURLY EVERY 1 HOUR. Or there are options for BETWEEN start and end times (STARTS CONCAT(DATE(now()), ' ', '08:00:00') ENDS CONCAT(DATE(now()), ' ', '18:01:00'). But Seemingly no way to combine them:

Doing EVERY 1 HOUR STARTS... ENDS.... simply runs every hour between those two times, then stops. Come tomorrow it doesn't restart.

Upvotes: 0

Views: 445

Answers (1)

eggyal
eggyal

Reputation: 126025

You could run every hour and then, within the event body, check the time to see whether it should proceed or immediately terminate:

DELIMITER //

CREATE EVENT my_event ON SCHEDULE EVERY HOUR DO
IF CURRENT_TIME BETWEEN '08:00:00' AND '18:00:00' THEN
  -- do stuff
END IF//

DELIMITER ;

Upvotes: 3

Related Questions