What do the special characters mean?
What is Cron?
The Cron formatting used for bulk messaging notifications is a string composed of 5 fields separated by white/blank space in this order: [Minutes] [Hours] [Day of the Month] [Month] [Days of the Week].
| Minutes | Hours | Day of the Month | Month | Days of the Week | |
| Allowed Values | 0-59 | 0-23 | 1-31 | 1-12 or JAN-DEC | 1-7 or SUN-SAT |
| Allowed Special Characters | , - * / | , - * / | , - * ? / L W | , - * / | , - * ? / L # |
What do the special characters mean?
- Asterisk * = "all values". The asterisk, or star, is used to select all values within a field. For example, "*" in the minute field means "every minute".
- Question Mark ? = "no specific value". The question mark is useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if you want your task to run on a particular day of the month (such as the 15th), but don't care what day of the week that happens to be, you would put "15" in the day of the month field, and "?" in the day of the week field.
- Hyphen/Dash - The hyphen, or dash, is used to specify ranges. For example, "12-14" in the hour field means "12, 1, and 2pm".
- Comma , The comma is used to specify additional values. For example, "TUE,THU" in the day of the week field means "Tuesday and Thursday".
-
Slash / The slash is used to specify increments. For example, "*/3" in the hour field would mean 0, 3, 6, 9, 12, 15, 18, 21. The asterisk specifies "every hour," but the "/3" means only the first, fourth, seventh, etc. values.
- Another example: 1/5' in the day of the month field means "run every 5 days starting on the first day of the month".
-
L = "last". 'L' has a different meaning in each of the two fields where it can be used. For example, the value "L" in the day of the month field means "the last day of the month" - day 31 for January, day 28 for February in non-leap years. If used in the day of the week field by itself, it just means "7" or "SAT". But if used in the day of the week field after another value, it means "the last XXX day of the month" - for example "6L" means "the last Friday of the month". You can also specify an offset from the last day of the month, such as "L-3" which would mean the third-to-last day of the calendar month.
- When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing/unexpected results.
-
W = "weekday". 'W' is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day of the month field, it would mean: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will run on Friday the 14th. If the 15th is a Sunday, the trigger will run on Monday the 16th. If the 15th is a Tuesday, then it will run on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will run on Monday the 3rd, as it will not 'jump' over the boundary of a month's days.
- The 'W' character can only be specified when the day of the month is a single day, not a range or list of days.
- The 'L' and 'W' characters can also be combined in the day of the month field to yield 'LW', which translates to the "last weekday of the month".
-
Pound Sign # The pound sign, or hashtag, is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day of the week field means "the third Friday of the month" (day 6 = Friday and "#3" = the 3rd one in the month). Other examples:
- "2#1" = the first Monday of the month
- "4#5" = the fifth Wednesday of the month.
- Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.
- The legal characters and the names of months and days of the week are not case sensitive. MON is the same as mon.
Examples
| Cron expression | Frequency |
|---|---|
| 0 12 * * ? | 12 pm (noon) every day |
| 15 10 ? * * | 10:15am every day |
| 15 14 ? 3 TUE,THU | 2:15pm every Tuesday and Thursday during March |
| 15 14 ? * MON-FRI | 2:15pm every day from Monday - Friday |
| 30 16 15 * ? | 4:30pm on the 15th day of every month |
| 15 10 L * ? | 10:15am on the last day of every month |
| 15 10 ? * 6L | 10:15am on the last Friday of every month |
| 15 10 ? * 6#3 | 10:15am on the third Friday of every month |
| 45 10 ? * 2#1 | 10:45am on the first Monday of every month |
| 11 11 11 11 ? | 11:11am on every November 11th |