How-to guide

How to Write a Cron Expression

A cron expression has five fields in a fixed order: minute, hour, day of month, month, and day of week. An asterisk means every value, a slash sets a step, and a comma lists several. The commonest mistake is leaving the minute as an asterisk, which runs the job sixty times an hour rather than once.

Cron Expression Generator

Build a cron expression from a schedule, and see when it will run.

Open the tool

Cron syntax is compact rather than complicated, but it is written left to right in increasing units except for the last field, which is why people misread it. Once you know the order, an unfamiliar expression can be read in a few seconds.

Almost every cron accident is one of two mistakes: an asterisk left in the minute field, or a misunderstanding of how the two day fields combine. Both produce a job that runs far more often than anybody intended.

Step by step

  1. Learn the five fields in order

    Minute 0-59, hour 0-23, day of month 1-31, month 1-12, day of week 0-6 with Sunday as 0. So 30 2 * * * is 02:30 every day. Some systems accept a sixth field for seconds at the front, which is a common source of off-by-one-field confusion.

  2. Always pin the minute

    Writing * * * * * runs the job every minute. To run hourly you need a specific minute: 0 * * * * runs at the top of each hour. An asterisk in the minute field is the single most expensive typo in cron.

  3. Use steps and ranges rather than long lists

    */15 in the minute field means every fifteen minutes. 9-17 in the hour field means nine in the morning to five in the afternoon inclusive. Combining them, 0 9-17/2 * * * runs every two hours during office hours.

  4. Understand how the two day fields combine

    When both day of month and day of week are restricted, cron runs the job if either matches, not both. So 0 0 1 * 1 runs on the first of the month and on every Monday. To restrict by weekday only, leave day of month as an asterisk.

  5. Confirm the timezone before you rely on it

    Cron uses the server timezone unless told otherwise, so a schedule written for local time may drift by an hour when daylight saving changes. Jobs scheduled between one and three in the morning can run twice or not at all on the changeover night.

Example

Four schedules, from most to least frequent.

Expression

*/5 * * * *
0 3 * * *
0 9 * * 1-5
0 0 1 1 *

Meaning

every 5 minutes
03:00 every day
09:00 Monday to Friday
midnight on 1 January

Frequently asked questions

What does * * * * * mean?
Every minute of every hour of every day — 1,440 runs a day. It is almost never what is wanted, and it is the usual reason a job that should run hourly floods a queue or a log.
How do I run a job every 15 minutes?
Use a step value in the minute field: */15 * * * *. That fires at :00, :15, :30 and :45. Writing 15 * * * * instead runs once an hour, at quarter past — a common and easily missed difference.
Why does my job run on days I did not expect?
Because when both day of month and day of week are restricted, cron treats them as OR rather than AND. 0 0 13 * 5 runs on the thirteenth and on every Friday, not only on Friday the thirteenth.
Is Sunday 0 or 7?
Both, on most Unix implementations — 0 and 7 each mean Sunday. Names such as SUN and MON are also widely accepted. Numeric 0 is the safest choice if the expression may move between systems.
What happens during a daylight saving change?
A job scheduled in the hour that is skipped may not run at all, and one in the hour that repeats may run twice. If the timing matters, schedule outside the one-to-three window or run the server clock in UTC.

Tools used in this guide

All tools →
All guides →

Last reviewed .