CRON
Expression interpreter
of month
of week
Name | Required | Allowed values | Allowed special characters |
---|---|---|---|
seconds | Yes | 0-59 | , - * / |
minutes | Yes | 0-59 | , - * / |
hours | Yes | 0-23 | , - * / |
days of month | Yes | 1-31 | , - * ? / L W C |
months | Yes | 0-11 or JAN-DEC | , - * / |
days of week | Yes | 1-7 or SUN-SAT | , - * ? / L C # |
years | No | empty or 1970-2099 | , - * / |
Sign | Explanation |
---|---|
, | Separates consecutive values. |
- | Specifies a range from-to. |
* | All values for the field, e.g., in the hour field means 'every hour'. |
? | Useful when it is necessary to specify a value in one of two fields where the character is allowed but not in the other. For example, if I want the trigger to run on the 5th day of the month but don't care about which day of the week it is, I will put '5' in the day of the month field and '?' in the day of the week field. |
/ | Used to specify steps. The first value indicates when the step starts, and the second value indicates how often the step will be performed, e.g., '0/15' in the minute field means minutes 0, 15, 30, 45, while '5/15' means execution at minute 5, 20, 35, and 50. |
# | The hash '#' is used to specify the 'nth' day of the month, e.g., value '4#3' in the day of the week field means the third Thursday of the month (day 4 = Thursday and #3 = third Thursday of the month). |
L | The letter 'L' means 'last' in the day of the week or day of the month fields. For example, '0 0 9 ? * 3L' means the last Tuesday of every month at 9 AM. In the day of the month field, you can also specify 'LW', meaning the last weekday of the month. |
W | Specifies the nearest weekday (Monday to Friday) to the given day of the month. For example, '1W' means 'nearest weekday to the 1st day of the month'. If the 1st falls on a Sunday, the cron will be triggered on Monday, the 2nd of the month. |
C | This shorthand means 'calendar' and indicates that values are calculated taking into account the associated calendar, if one exists. When no calendar is associated, it is treated as having a calendar covering all days. For example, the value '3C' in the day of the month field means 'the first day included in the calendar after the 3rd day of the month'. While '1C' in the day of the week field means 'the first day included in the calendar on Sunday or after'. |
Expression | Description |
---|---|
0 0 12 * * ? | Execute every day at 12:00. |
0 0/20 * * * ? | Execute every 20 minutes, at minutes 0, 20, 40. |
0 15 10 * * ? 2023 | Execute at 10:15 every day in the year 2023. |
* 30 3 * * 1,7 | Execute every second at 3:30 on Saturday and Sunday. |