Reputation: 1481
I need an event that subtracts the current date from a specific date entered.
However, I am working with a criteria of 1 month, if the result of the subtraction is greater than 1 months then update a table with value '1'. So it would Be Current_date- receipt_date
, and if this is greater than 1 months then update flag to be '1' else '0'.
I want it to run every minute.
Here's my code so far:
CREATE EVENT myevent3
ON SCHEDULE EVERY '1' MINUTE
DO
UPDATE lms.receipt
SET delinquent = (
CASE WHEN DATE_ADD( receipt_date, INTERVAL 1 MONTH ) < NOW()
THEN 1
ELSE 0
END
);
Upvotes: 0
Views: 78
Reputation: 180917
To make your events run, you need to enable the event scheduler using set global event_scheduler=on
. That will enable the event scheduler until the next server restart.
If you want it persistent through server restarts, you will need to add this line to your my.cnf in the [mysqld]
section;
event_scheduler=ON
(Reference documentation here)
Upvotes: 1
Reputation: 47321
When you are writing a result, you can't expect you can return a result at the same time.
You can use cronjob consists of two queries that run every minute to replace the event
Upvotes: 0