2

i want to read my table logs after rotating my logs using an event and i want my event to run in any day of the week i choose.

After doing some research,i have come up with this

CREATE EVENT read_rotated_logs
ON SCHEDULE
  EVERY 1 WEEK
  STARTS CURRENT_DATE + INTERVAL 7 - WEEKDAY(CURRENT_DATE) DAY
    DO BEGIN

    END */$$
DELIMITER ;

Its not clear how i might arrive at a specific day of the week for example monday.How may i structure my code to make the event run on any speific day of the week (mon or tuesday or wednesday or thursday or friday or saturday or sunday)

Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
  • http://www.java2s.com/Code/SQL/Event/Eventscheduleeveryweek.htm – Mihai Aug 28 '14 at 12:13
  • I have just written this `select dayofweek(curdate());` from http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayofweek looks promising.Let me study the link,looks interesting. –  Aug 28 '14 at 12:16
  • @Mihai In the link,its as if mysql has a notion of days of the week like in the ordinary English Gregorian calendar. –  Aug 28 '14 at 12:20

1 Answers1

4

Here is how you do it for the other days of the week

Monday

STARTS CURRENT_DATE + INTERVAL 0 - WEEKDAY(CURRENT_DATE) DAY

Tuesday

STARTS CURRENT_DATE + INTERVAL 1 - WEEKDAY(CURRENT_DATE) DAY

and so on

catalinetu
  • 630
  • 6
  • 12
  • Hi,how do i add a specific time on `STARTS CURRENT_DATE + INTERVAL 3 - WEEKDAY(CURRENT_DATE) DAY` –  Aug 28 '14 at 12:48
  • you can do something like this `CURRENT_TIMESTAMP + INTERVAL 7 - WEEKDAY(CURRENT_TIMESTAMP) DAY + INTERVAL 1 HOUR` and play with + INTERVAL 1 HOUR to be on your desired hour – catalinetu Aug 28 '14 at 13:08
  • Isn't there any way to set the time explicitly like `11:00 a.m`? –  Aug 28 '14 at 13:12
  • you can try like this `CONCAT(CURRENT_DATE + INTERVAL 7 - WEEKDAY(CURRENT_DATE) DAY,' 11:00:00')` – catalinetu Aug 28 '14 at 13:20
  • Is it mandatory for time in an event to be in 24 hour format?. –  Aug 28 '14 at 13:33