HumbleLearner
HumbleLearner

Reputation: 103

How do I generate monthly events?

I want to create a monthly event for every registered customer that fires an insert statement on billing table. If an event is specified to run from say 20th Aug 2013 0:00 hrs (a future date), on what date can I expect next event to occur?

I don't know whether to assume it as 30 days or 365/12 days (mathematically).

I am using something like this to create that event:

DELIMITER $$
CREATE EVENT event1
ON SCHEDULE EVERY '1' MONTH
STARTS '2013-08-20 00:00:00'
DO 
BEGIN

END$$

DELIMITER ;

My question is when does mysql fire this event in the next month?

Upvotes: 1

Views: 119

Answers (1)

Alex
Alex

Reputation: 7833

Rescheduled events rely on the date interval function of MySQL. Your event would reoccur on:

SELECT DATE_ADD('2013-08-20', INTERVAL 1 MONTH)

that's 2013-09-20.

Fore more details about the date functions, see: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

Upvotes: 1

Related Questions