How to read a crontab line

A cron expression has five fields: minute (0-59), hour (0-23), day of the month (1-31), month (1-12) and day of the week (0-7, where 0 and 7 are Sunday). An asterisk means “any”, a comma separates values, a hyphen gives a range and a slash a step: */15 in the minutes means 0, 15, 30 and 45.

So 0 9 * * 1-5 runs the job at 9:00 Monday to Friday, 30 2 1 * * at 2:30 on the first of each month, */10 * * * * every ten minutes. Macros are shorthands: @daily equals 0 0 * * *, @hourly 0 * * * *, @weekly 0 0 * * 0.

One exception surprises many people: when both the day of the month and the day of the week differ from *, cron runs the job when either is true. 0 12 1 * 1 does not mean “the first of the month if it is a Monday” but “every first of the month and every Monday”.

Common mistakes

  • Writing * * * * * meaning “once a day”: it means every minute.
  • Forgetting that cron uses the server's time zone, not the viewer's: the next runs here are in your browser's time zone.
  • Expecting a job on the 31st of every month: in 30-day months and February it simply does not run.

Frequently asked questions

Does cron support seconds?

Classic cron does not: the smallest unit is the minute. Some systems, such as Quartz or Spring, add a sixth field for seconds, but with a different syntax.

What happens with daylight saving time?

On the night the clocks go forward a job at 2:30 can be skipped; when they go back it can run twice. That is why important jobs are scheduled outside the 2-3 a.m. window or in UTC.

Can I use day and month names?

Yes: MON-FRI for days and JAN-DEC for months, in English and in any case.

How this calculation works

Each field is expanded into the set of allowed values: * is the whole range, a-b a range, x/n the values from x onwards in steps of n, and comma-separated lists are merged. In the weekday field 7 becomes 0 (Sunday). A day qualifies when its month is allowed and, when both day fields are restricted, when either the day of the month or the weekday is. The next runs are searched day by day, up to eight years ahead, in the browser's time zone.