Mc Doc
Mc Doc

Reputation: 1

MYSQL - check a time and execute query

I'd like (if it possible) check a time and if time = special time, make update of the table.

My idea:

select current_time()
if current_time = 15:19 
{
   update tasks set finished = replace (finished, '1', '0')
}

Do you have any ideas???

Upvotes: 0

Views: 62

Answers (1)

juergen d
juergen d

Reputation: 204746

Use an event for that

delimiter //
CREATE EVENT IF NOT EXISTS your_event
ON SCHEDULE EVERY 1 DAY 
STARTS  '2014-07-04 15:19:00'
ON COMPLETION PRESERVE ENABLE
DO
    update tasks 
    set finished = replace (finished, '1', '0');
//

It will be executed automatically every day on the defined time.

Upvotes: 2

Related Questions