learn

Cron syntax: how to read and write a cron expression

Read any cron expression: the five fields, *, comma, dash and slash, @daily shortcuts, Quartz and AWS differences, time zones and the examples people need.

Reading a cron expression

A cron expression tells a scheduler when to run a job. The classic Unix form has five fields separated by spaces: minute, hour, day of month, month and day of week. 30 2 * * 0 means "at 02:30 every Sunday". Each field accepts a value, a list, a range or a step, and * means "every". The rules are simple, but platforms differ in small ways that cause jobs to run at the wrong time, so it pays to check an expression before deploying it. The crontab generator explains any expression in words.

The five fields

FieldValuesExample
Minute0–5915
Hour0–239
Day of month1–311
Month1–12 or JAN–DEC*/3
Day of week0–7 (0 and 7 are Sunday) or SUN–SAT1-5

Operators: * any value, , a list (1,15), - a range (9-17), / a step (*/10 = every 10 units). When both day of month and day of week are restricted, classic cron runs the job when either matches, which surprises many people: 0 0 1 * 1 runs on the 1st of the month and also on every Monday.

Common expressions

*/15 * * * *     every 15 minutes
0 * * * *        at the start of every hour
0 */6 * * *      every 6 hours (00:00, 06:00, 12:00, 18:00)
0 9 * * 1-5      at 09:00 on weekdays
0 0 * * *        every day at midnight (same as @daily)
0 0 1 * *        at midnight on the 1st of each month (@monthly)
30 2 * * 0       at 02:30 every Sunday
0 8 1 1,4,7,10 * at 08:00 on the first day of each quarter

Shortcuts understood by most crons: @reboot, @hourly, @daily (or @midnight), @weekly, @monthly, @yearly (or @annually).

Platform differences

  • Quartz (Java, Spring's @Scheduled uses a similar 6-field form) adds a seconds field first and an optional year last, and uses ? for "no specific value" in day of month or day of week. 0 0 9 ? * MON-FRI is 09:00 on weekdays.
  • AWS EventBridge rules use six fields, cron(minute hour day-of-month month day-of-week year), require ? in one of the two day fields, and run in UTC.
  • GitHub Actions schedules use five fields in UTC and do not run more often than every 5 minutes.
  • Kubernetes CronJob uses five fields and accepts a timeZone setting.

Time zones and daylight saving

Cron runs in the time zone of the machine or service, often UTC in the cloud. A job at 0 9 * * * in UTC runs at 06:00 in São Paulo (UTC−3). Where daylight saving applies, a job between 01:00 and 03:00 may run twice or not at all on the change days; schedule important jobs outside that window. Convert times with the date converter and see Unix timestamps for why servers prefer UTC. To see one schedule in several cities at once, use the time zone converter.

FAQ

How do I run a cron job every 5 minutes?

Use */5 * * * *. In Quartz, add the seconds field: 0 */5 * * * ?.

Does 0 or 7 mean Sunday?

Both, in most cron implementations. MON–SUN names avoid the doubt where they are supported.

Why did my job not run at the time I expected?

Usually the time zone (UTC on the server), a day-of-month and day-of-week combination read as "or", or a 6-field expression given to a 5-field cron.

Can cron run a job every 90 minutes?

Not with a single expression, because steps restart every hour. Use two lines, 0 0-21/3 * * * and 30 1-22/3 * * *, or a scheduler that supports intervals.