All Products
Search
Document Center

CRON Expression

Last Updated: Aug 21, 2020

A Cron expression is a string separated by five or six spaces and divided into six or seven domains, each of which represents a meaning. There are two syntax formats for Cron:

  • Second minute hour date month week year
  • Second minute hour date month week

Allowed Fields and Values

Name Allowed value Allowed special characters Remarks
Second 0-59 - * /
Minute 0-59 - * /
Hour 0-23 - * /
Date 1-31 - * ? / L W C
Month 1-12 JAN-DEC - * /
Week 1-7 SUN-SAT - * ? / L C # 1 for Sunday, 2 for Monday, and so on
Year (optional) Leave it blank, 1970-2099 , - * / The value is automatically generated, and the tool does not display the value.

Special Characters

Character Meaning Example
* Represents any value of the matching domain. For example, if you use the asterisk (*) for the minute domain, a task is triggered every minute.
? Represents any value of the matching domain, but it can only be used for the date and week domains, because these two domains affect each other. For example, to trigger a task on the 20th day of each month, regardless of the day of the week, you can only use the following expression: 13 13 15 20 * ?. That is, you can only use the question mark (?) instead of the asterisk (*) for the week domain. If you use the asterisk (*), the task will be triggered every day in a week, which conflicts with the restriction specified by the date domain. That is, the expression is incorrect.
- Specifies a range. For example, if you use 5-20 for the minute domain, a task is triggered every minute in the period of the fifth to twentieth minutes.
/ Specifies that a task is initially triggered at the start time, and then it will be triggered at a fixed interval. For example, if you use 5/20 for the minute domain, the task is triggered at the fifth, twenty-fifth, and forty-fifth minutes.
, Enumerates values. For example, if you use 5,20 for the minute domain, a task is triggered at the fifth and twentieth minutes.
L Represents the last one. This special character applies only to the day and week domains. For example, if you use 5L for the week domain, a task is triggered on the last Thursday.
W Indicates a valid working day (Monday to Friday) and only applies to the day domain. The system will trigger the task on the valid working day that is closest to the specified day. For example, if you use 5W for the day domain and the 5th is Saturday, the system will trigger the task on the working day that is closest to Friday, that is, the 4th. If the 5th is Sunday, the system will trigger the task on the 6th (Monday). If the 5th is a working day, the system will trigger the task on the 5th. In addition, the W search does not cross months.
LW Represents the last working day of a month, that is, the last Friday of the month.
# Represents a specific day of the week in a month. This special character applies only to the week domain. For example, if you use 4#2 for the week domain, a task is triggered on the second Wednesday in a month. That is, in this string, 4 represents Wednesday and 2 represents the second one.

Example

  • */5 * * * * ? Run every 5 seconds
  • 0 */1 * * * ? Run every 1 minute
  • 0 0 2 1 * ? * Run at 2 a.m. on the 1st of each month
  • 0 15 10 ? * MON-FRI Run at 10:15 a.m. every day from Monday to Friday
  • 0 15 10 ? 6L 2002-2006 Run at 10:15 a.m on the last Friday of each month from 2002 to 2006
  • 0 0 23 * * ? Run at 23:00 every day
  • 0 0 1 * * ? Run at 1 a.m. every day
  • 0 0 1 1 * ? Run at 1 a.m. on the 1st of each month
  • 0 0 23 L * ? Run at 23:00 on the last day of each month
  • 0 0 1 ? * L Run at 1 a.m. on Sunday of each week
  • 0 26,29,33 * * * ? Run at every 26, 29, and 33 minutes
  • 0 0 0,13,18,21 * * ? Run at 00:00, 13:00, 18:00, and 21:00 every day
  • 0 0 10,14,16 * * ? Run at 10 a.m. 2 p.m. and 4 p.m. every day
  • 0 0/30 9-17 * * ? Run every half an hour in the working hours of 9 a.m. to 5 p.m.
  • 0 0 12 ? * WED Run at 12 noon every Wednesday
  • 0 0 12 * * ? Run at 12 noon every day
  • 0 15 10 ? * * Run at 10:15 a.m. every day
  • 0 15 10 * * ? Run at 10:15 a.m. every day
  • 0 15 10 * * ? * Run at 10:15 a.m. every day
  • 0 15 10 * * ? 2005 Run at 10:15 a.m. every day in 2005
  • 0 * 14 * * ? Run every 1 minute between 2 p.m. and 2:59 p.m. every day
  • 0 0/5 14 * * ? Run every 5 minutes between 2 p.m. and 2:55 p.m. every day
  • 0 0/5 14,18 * * ? Run every 5 minutes between 2 p.m. and 2:55 p.m. and between 6 p.m. and 6:55 p.m. every day
  • 0 0-5 14 * * ? Run every 1 minute between 2 p.m. and 2:05 p.m. every day
  • 0 10,44 14 ? 3 WED Run at 2:10 p.m and 2:44 p.m. on Wednesday of March every year
  • 0 15 10 ? * MON-FRI Run at 10:15 a.m. from Monday to Friday
  • 0 15 10 15 * ? Run at 10:15 a.m on the 15th of each month
  • 0 15 10 L * ? Run at 10:15 a.m. on the last day of each month
  • 0 15 10 ? * 6L Run at 10:15 a.m. on the last Friday of each month
  • 0 15 10 ? * 6L 2002-2005 Run at 10:15 a.m. on the last Friday of each month from 2002 to 2005
  • 0 15 10 ? * 6#3 Run at 10:15 a.m. on the third Friday of each month