Syntax for the schedule expression
The schedule expression is used to define the schedule for the job to be executed. The schedule expression is defined using the CRON syntax.
This table lists the syntax for the job scheduler command:
Field Name | Allowed Values | Allowed Special Characters |
---|---|---|
Minutes | 0-59 | , - * / |
Hours | 0-23 | , - * / |
Day of Month | 1-31 | , - * ? / L W |
Month | 1-12 or JAN-DEC | , - * / |
Day of Week | 1-7 or SUN-SAT | , - * ? L # |
Year (optional) | NULL or 1970 - 2199 | , - * / |
Exception (optional) | 1-31, 1-12 or JAN-DEC | , - * ? / L # W |
The # character is used in the Day of Week field to specify "the nth" XXX day of the month. These are a few examples:
- The value of 6#3 in the Day of Week field means the third Friday of the month (day 6 = Friday and #3 = the 3rd one in the month).
- The value of 2#1 in the Day of Week field means the first Monday of the month.
- The value of 4#5 means, the fifth Wednesday of the month.
- If you specify #5 and the value (5) is not valid for the day-of-week in the month, no trigger occurs that month. For example 6#5 means, the 5th Friday of the month. If the month does not contain 5 Fridays, the job is not executed.
- If the # character is used, only one expression in the Day of Week field can be used (3#1, 6#3 is not valid, since two expressions exist).
The * character cannot be used as a value in the Day of Week and Day of Month fields in the same expression, the valid form is either * * * * ?, or * * ? * *.
The ! character allows supporting expressions with exceptions. This character separates the main cron expression with the cron exception. The exception separator and exception expression are optional. When an exception is defined, each possible date (from the main expression) is verified against the exception. The matching dates are excluded, and the next possible date is considered from the main expression. If the valid date does not exist within the first 1000 dates, an exception is generated to prevent infinite loops.
This is an example of the expression:
0 0 ? * 2-7 ! 0 0 L * ?
- Main expression: 0 0 ? * 2-7, which means daily at midnight on days 2 - 7 (MON - SAT).
- Exception expression: 0 0 L * ?, which means the last day of the month.
Therefore, the full expression evaluates to execute daily at midnight on days 2 - 7 (MON - SAT), except on the last day of the month.
This table lists the special characters that can be used in the syntax of the schedule expression:
Special Characters | Usage |
---|---|
Comma (,) | This character is used to specify the additional values. For example, if "MON,WED,FRI" is specified in the Day of Week field, then the days are Monday, Wednesday, and Friday respectively. |
Hyphen (-) | This character is used to specify the range. For example, if "10-12" is specified in the hour field, then the hours are 10, 11, and 12 respectively. |
Asterisk (*) | This character is used to specify all the values. For example, if "*" is specified in the minutes field, then every minute is considered. |
Slash (/) | This character is used to specify increments. For example, if "0/15" is specified in the seconds field, then the seconds are 0, 15, 30, 45, and 60. If "5/15" is specified in the seconds field, then the seconds are 5, 20, 35, and 50 respectively. The form "*/..." is equal to the form "first-last/...", that is, an increment over the largest possible range of the field. |
Question Mark (?) | This character is used in the Day of Month and Day of Week fields. This is used to specify 'No Specific Value' and when one of the two fields must be specified, but not the other. For example, to execute the syntax on a particular day of the month (10th), but not a specific day of the week, the specify "10" in the Day of Month field, and "?" in the Day of Week field. |
L (Last) | This character is used in Day of Month and Day of Week fields. For example, if you specify "L" in the Day of Month field, then the day is the last day of the month. If "L" is specified in the Day of Week field, then the day is "7" or "SAT". But if "L" is specified in the Day of Week field after another value, then the day is "the last xxx day of the month" - for example "6L" means "the last Friday of the month". When using the 'L' option, the lists, or ranges of values must not be specified. |
W | This is used in Day of Month field to specify the weekday nearest to the specified day. For example, if you specify 15W in the Day of Month field, the day is "nearest day to the 15th of the month". If 15th of the month is Saturday, 14th is the Day of Month; if the 15th is Sunday, 16th is Day of Month. |