Skip to main content

Cron Expressions Explained

How the five fields of a standard cron expression work, with common patterns and the rule that trips people up.

The five fields

A standard cron expression has five space-separated fields, in this order: minute (0-59), hour (0-23), day of the month (1-31), month (1-12) and day of the week (0-6, where both 0 and 7 mean Sunday depending on the implementation). A job that should run at 09:00 on weekdays is written as 0 9 * * 1-5.

Values, ranges, lists and steps

Each field accepts more than a single number. An asterisk (*) means every value. A range like 1-5 means every value from 1 to 5 inclusive. A comma-separated list like 1,3,5 means exactly those values. A step like */15 means every 15th value starting from the field's minimum, so */15 in the minute field matches 0, 15, 30 and 45.

These can combine: 0 9-17/2 * * 1-5 means the top of the hour, every 2 hours from 9 to 17, on weekdays.

The day-of-month and day-of-week trap

If both the day-of-month and day-of-week fields are restricted (neither is *), standard cron treats them as an OR, not an AND: the job runs when either condition is true. For example 0 0 1 * 1 does not mean “the first of the month, but only if it's a Monday”; it means “every 1st of the month, and also every Monday.” To mean only the first Monday of the month, most schedulers need a different mechanism entirely, since standard cron cannot express that.

Shortcuts and variants

Many cron implementations accept shortcuts like @daily, @hourly and @weekly as aliases for common five-field expressions. Some schedulers (such as Quartz, used by many Java applications) add a sixth field for seconds and sometimes a seventh for the year; those expressions look similar but are not interchangeable with standard 5-field cron, so double-check which flavour a given system expects before pasting one in.