Cron expressions

Updated at:

This topic describes the syntax rules and usage of Cron expressions in Alibaba Cloud IDaaS EIAM. It helps you correctly configure scheduled tasks.

What is a Cron expression?

A Cron expression is a time expression used to configure scheduled tasks. It is a string that consists of 6 or 7 fields separated by spaces. Each field represents a time unit.

Basic syntax

  1. Cron syntax format:

    Seconds Minutes Hours Day of month Month Day of week [Year]

  2. Values allowed for each field

    Field position

    Time unit

    Value range

    Allowed special characters

    1

    Seconds

    0–59

    - * /

    2

    Minutes

    0–59

    - * /

    3

    Hours

    0–23

    - * /

    4

    Day of month

    1–31

    - * ? / L W C

    5

    Month

    1–12 or JAN–DEC

    JAN-DEC - * /

    6

    Day of week

    0–7 (both 0 and 7 indicate Sunday) or SUN–SAT

    SUN-SAT - * ? / L C #

    7 (optional)

    Year

    Leave blank or use 1970–2199 (optional field).

    , - * /

Special characters

Character

Meaning

Description

*

Indicates any value of the field.

Using * in the Minutes field triggers the event every minute.

?

Indicates any value of the field. However, it can be used only in the Day of month and Day of week fields because these fields affect each other.

To trigger the schedule on the 20th of each month regardless of the day of the week, use only the following expression: 13 13 15 20 * ?. The Day of month field already specifies the 20th. Therefore, the final Day of week field can use only ?, not *. Using * in the final field triggers the event regardless of the day of the week. This conflicts with the 20th specified in the Day of month field and makes the expression invalid.

-

Indicates a range of values.

Using 5-20 in the Minutes field triggers the event every minute from minute 5 to minute 20.

/

Indicates an event that starts at the specified value and then recurs at a fixed interval.

Using 5/20 in the Minutes field triggers the event at minute 5 and then every 20 minutes. It triggers at minutes 5, 25, and 45.

,

Indicates enumerated values.

Using 5,20 in the Minutes field triggers the event every minute at minutes 5 and 20.

L

Indicates the last value. This character can appear only in the Day of month and Day of week fields.

Using 5L in the Day of week field triggers the event on the last Thursday.

W

Indicates a business day (Monday to Friday). This character can appear only in the Day of month field. The system triggers the event on the business day closest to the specified date.

Using 5W in the Day of month field triggers the event on Friday the 4th when the 5th is a Saturday. When the 5th is a Sunday, the event triggers on Monday the 6th. If the 5th is a business day, the event triggers on the 5th. The nearest-match search for W does not cross month boundaries.

LW

These characters can be used together. They indicate the last business day of a month, that is, the last Friday.

#

Indicates the Nth day of the week in a month. This character can appear only in the Day of week field.

Using 4#2 in the Day of week field triggers the event on the second Wednesday of a month. In this expression, 4 indicates Wednesday, and 2 indicates the second occurrence.

Common examples

Warning

Cron expressions in the IDaaS identity provider require an interval of at least 1 hour. Set the interval appropriately so that the data synchronization frequency meets your expectations.

Example

Description

0 0 */2 * * ?

Runs every 2 hours.

0 0 2 1 * ?

Runs at 02:00 on the 1st of each month.

0 15 10 ? * MON-FRI

Runs the job at 10:15 every day from Monday to Friday.

0 0 23 * * ?

Runs at 23:00 every day.

0 0 1 * * ?

Runs at 01:00 every day.

0 0 1 1 * ?

Runs at 01:00 on the 1st of each month.

0 0 23 L * ?

Runs at 23:00 on the last day of each month.

0 0 1 ? * L

Runs at 01:00 every Sunday.

0 0 0,13,18,21 * * ?

Runs at 00:00, 13:00, 18:00, and 21:00 every day.

0 0 10,14,16 * * ?

Runs at 10:00, 14:00, and 16:00 every day.

0 0 12 ? * WED

Runs at 12:00 every Wednesday.

0 0 12 * * ?

Triggers at 12:00 every day.

0 15 10 ? * *

Triggers at 10:15 every day.

0 15 10 * * ?

Triggers at 10:15 every day.

0 15 10 * * ? *

Triggers at 10:15 every day.

0 15 10 * * ? 2025

Triggers at 10:15 every day in 2025.

0 15 10 15 * ?

Triggers at 10:15 on the 15th of each month.

0 15 10 L * ?

Triggers at 10:15 on the last day of each month.

0 15 10 ? * 6L

Triggers at 10:15 on the last Friday of each month.

0 15 10 ? * 6L 2025-2026

Triggers at 10:15 on the last Friday of each month from 2025 to 2026.

0 15 10 ? * 6#3

Triggers at 10:15 on the third Friday of each month.

Note

You can adjust the time parameters in these examples, including the year, based on your requirements.