如何在特定时间从星期一到星期五创建MYSQL预定事件?

时间:2015-11-20 22:48:44

标签: mysql events schedule dayofweek

我有这段代码:

CREATE EVENT event1
ON SCHEDULE EVERY 1 DAY
STARTS '2015-11-20 23:00:00'
DO
UPDATE users SET username='verde' WHERE id=1;

帮助,我的代码每天23:00更新用户,但我只希望从星期一到星期五更新用户。

1 个答案:

答案 0 :(得分:2)

基于此处的逻辑http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayofweek

CREATE EVENT event1
ON SCHEDULE EVERY 1 DAY
STARTS '2015-11-20 23:00:00'
DO
  IF DAYOFWEEK(curdate()) BETWEEN 2 AND 6 THEN
  UPDATE users SET username='verde' WHERE id=1;
  END IF;