A CRON expression is used to configure specific instances of a trigger. Mostly for scheduled repetitive triggering. It is a string consisting of 6 or 7 fields that represent individual values of the schedule. These fields are separated by space and contain any of the allowed values in various combinations.
CRON expression can be as simple as this: * * * * ? * or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2012-2020
List of values you can use in the CRON expression:
CRON expression syntax is following:
Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 6th field (day of the week) means Mondays, Wednesdays and Fridays.
Defines ranges. For example, 2012-2020 indicates every year between 2012 and 2020, inclusive.
Used to select all possible values within a field. For example, * in the minute field means every minute. The wild card cannot be used in day of the week field.
Question mark (?)
When choosing a specific day, you can specify either day of the month or day of the week. You cannot specify both. If you specify day of the month, you must use ? for day of the week and vice versa. For example, if you want the trigger to fire on a particular day of the month (say, the 10th), but don’t care what day of the week that happens to be, put 10 in the day of the month field and ? in the day of the week field.
Used to specify “the nth” day of the month. For example, the value of 4#3 in the day of the week field means the third Thursday of the month (day 4 = Thursday and #3 = the 3rd Thursday in the month). If you specify #5 and there isn't 5th of the given day of the week in the month, then the trigger will not fire that month.
Describes increments of a range. For example 3-59/15 in the 2nd field (minutes) indicate the third minute of the hour and every 15 minutes thereafter.
When used in the day of the week field, it allows you to specify constructs such as the last Friday (5L) of a given month. In the day of the month field, it specifies the last day of the month. For example, day 31 for January, day 28 for February on non-leap years.
The W character is allowed for the day of the month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you specify 15W as the value for the day of the month field, the meaning is the nearest weekday to the 15th of the month. So, if the 15th is a Saturday, the trigger fires on Friday the 14th. If the 15th is a Sunday, the trigger fires on Monday the 16th. However, if you specify 1W as the value for day of the month, and the 1st is a Saturday, the trigger fires on Monday the 3rd, as it does not jump over the boundary of a month's days.
The R is a special ERA CRON expression character that allows you to specify randomized time moments. For example, R 0 0 * * ? * trigger fires every day at 00:00 but at a random second (0-59).
Real examples that illustrate some variations of the CRON expression: