user3368855
user3368855

Reputation: 51

Event in Mysql that runs only on weekdays

I want to create an event in mysql that runs only on weekdays and inserts a row in a table. I am able to create a even that runs everyday or after n number of days but am unable to do what I intend to do. i.e. Event for weekdays only.

Any help will be highly appreciated.

Thanx in advance

Upvotes: 2

Views: 2150

Answers (2)

juergen d
juergen d

Reputation: 204746

You can run the event every day and just do nothing if it is not a weekday with an if condition

delimiter //
CREATE EVENT IF NOT EXISTS your_event
ON SCHEDULE EVERY 1 DAY ON COMPLETION PRESERVE ENABLE
DO
    if DAYOFWEEK(curdate()) between 2 and 6 then
        Delete from attendance 
        where Att_mnth=Month(CurDate()) 
        and Att_day=DayOfMonth(CurDate());
    end if;
//

Upvotes: 3

user1413338
user1413338

Reputation:

You should make use of the DAYOFWEEK(date) MySQL function: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayofweek

If DAYOFWEEK(date) returns 7 or 1 (Saturday or Sunday) then you should skip the script.

Upvotes: 2

Related Questions