Wednesday, September 14, 2022

How to run MySQL event only on weekdays (Monday - Friday)

 I have a stored procedure that need to be execute automatically at 12 AM daily except Saturday and Sunday. In order to achieve this, here you need to use IF condition as screenshot below:

event


or create using below script:

delimiter //
CREATE EVENT IF NOT EXISTS your_event_name
ON SCHEDULE EVERY 1 DAY ON COMPLETION PRESERVE ENABLE
DO
    if DAYOFWEEK(curdate()) between 2 and 6 then
        call your_stored_procedure_name;
    end if;
//


Hope this may helps others

 

No comments:

Post a Comment