s.k.paul
s.k.paul

Reputation: 7291

Run MySQL event within specific time each day with specific interval

I have the following event_scheduler-

 CREATE EVENT my_schedule
 ON SCHEDULE EVERY 1 MINUTE
 STARTS CURRENT_TIMESTAMP 
 ENDS CURRENT_TIMESTAMP + INTERVAL 40 DAY
 DO
  BEGIN 
     -----
  END

It works fine. But now I would like to add another event which will run from 12:01AM to 02:00AM each day with 1 minute interval. Something like -

 CREATE EVENT new_schedule
 ON SCHEDULE EVERY 1 MINUTE
 STARTS 12:01AM 
 ENDS 02:00AM
 DO
  BEGIN 
    ------
  END

I'm new to MySQL event_scheduler. Please share your idea.

Upvotes: 0

Views: 41

Answers (1)

andychukse
andychukse

Reputation: 592

You can use if statement to check the timestamp before running within the specified interval

CREATE EVENT new_schedule
ON SCHEDULE EVERY 1 MINUTE
STARTS CURRENT_TIMESTAMP 
ENDS CURRENT_TIMESTAMP + INTERVAL 40 DAY
DO
  IF time(CURRENT_TIMESTAMP) between time('00:00:00') and time('02:00:00')
  then
     -----
  end if;

Upvotes: 2

Related Questions