Cron Expressions Explained
A cron expression is a short string that says when a job should run. The syntax is tiny, which is why people memorise just enough to be dangerous: a schedule that was meant to run once a day runs every minute, or never runs at all because of a time-zone assumption. This guide walks through the format and the places where it surprises people.
The five fields
Classic Unix cron (Vixie cron and its relatives) uses five space-separated fields:
+---------- minute 0-59
| +-------- hour 0-23
| | +------ day of month 1-31
| | | +---- month 1-12 (or JAN-DEC)
| | | | +-- day of week 0-7 (0 and 7 are Sunday; or SUN-SAT)
| | | | |
* * * * * command
A job fires when the current time matches every field. So 30 2 * * * means minute 30 of hour 2 on any day: 02:30 every day. A field containing * matches everything.
Ranges, lists and steps
Each field accepts a few operators that can be combined:
,lists values:0,30in the minute field is minute 0 and minute 30.-gives an inclusive range:1-5in the day-of-week field is Monday to Friday./gives a step:*/15in the minute field is every 15 minutes starting from 0, so 0, 15, 30 and 45. A range can take a step too:10-40/10is 10, 20, 30, 40.
Steps count from the start of the field's range, not from the moment you installed the job. */7 in the minute field gives 0, 7, 14, 21, 28, 35, 42, 49, 56, and then restarts at 0 in the next hour, so the gap between 56 and 0 is only four minutes. Steps divide evenly only when the step divides the range.
Examples and what they mean
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
*/15 * * * * | Every 15 minutes (:00, :15, :30, :45) |
0 * * * * | At the start of every hour |
0 */2 * * * | Every two hours at minute 0 (00:00, 02:00 ... 22:00) |
0 9 * * 1-5 | 09:00 on weekdays, Monday to Friday |
30 2 1 * * | 02:30 on the first day of every month |
0 0 * * 0 | Midnight at the start of Sunday |
0 0 1 1 * | Midnight on 1 January |
0 8,12,18 * * * | 08:00, 12:00 and 18:00 every day |
0 0 13 * 5 | Midnight on the 13th or on any Friday (see below) |
You can type any of these into our Cron Expression Builder. It has five boxes (minute, hour, day of month, month, day of week) plus the full expression field, the two stay in sync, and below them it prints a short description and the next ten run times in your browser's local time. Its description is deliberately terse (for instance, "minute 0, hour 9, day Monday to Friday"), so use the next-run list as the real check of what a schedule does. It accepts five fields only; a six-field Quartz string will show a warning.
Day of month and day of week: an OR, not an AND
This is the most misunderstood rule. When both the day-of-month and day-of-week fields are restricted (neither is *), standard cron runs the job when either matches. Many people write 0 0 13 * 5 expecting "Friday the 13th". It actually fires on every 13th and every Friday. If you want a true AND, schedule on the more frequent day and test the other condition inside the job, for example run every Friday and exit unless date +%d is 13.
Special strings and other dialects
Vixie-style cron also accepts shortcuts: @hourly, @daily, @weekly, @monthly, @yearly and @reboot. They are not universal. Schedulers that embed a cron parser may accept only the five numeric fields, or support just some of the shortcuts, and @reboot only makes sense on a machine that boots. Check the documentation of your platform (CI services, Kubernetes CronJobs, cloud schedulers) before relying on them.
Six and seven fields: Quartz and Spring
Java's Quartz scheduler and Spring's @Scheduled use a leading seconds field: second, minute, hour, day of month, month, day of week (Quartz also allows an optional trailing year). Because AND-ing the two day fields is not allowed there, Quartz requires a ? ("no specific value") in one of them:
0 0 12 ? * MON-FRI # 12:00:00 every weekday (Quartz)
0 15 10 * * ? # 10:15:00 every day
0 0/5 * * * * # every 5 minutes, on second 0 (Spring)
Shifting every field by one is the usual migration bug: pasting a five-field expression into Spring makes it fail to parse, and pasting a six-field one into a crontab is rejected or misread. Day-of-week numbering also differs between dialects (in Quartz 1 is Sunday), so names such as MON-FRI are safer than digits.
Time zones and daylight saving
Cron has no time-zone syntax. It uses whatever the scheduler's zone is: the server's local time for a system crontab, UTC for many cloud and CI schedulers, and a configurable zone in others. "Every day at 09:00" is only meaningful once you know which one. Servers should generally run in UTC, with local conversion done by humans. Our Timezone Converter helps you work out the UTC equivalent of a local business hour, and Unix Timestamps and Time Zones explains why UTC is the safe internal choice.
If the scheduler uses a zone with daylight saving time, local times can vanish or repeat. A job at 02:30 may be skipped on the night the clocks jump forward, since 02:30 does not exist, and some implementations run a job twice when the clocks go back. Behaviour varies by implementation, so avoid scheduling important jobs in the 01:00 to 03:00 window of a DST zone, or schedule in UTC.
Common mistakes
- Accidentally running every minute. Writing
* 3 * * *to mean "at 03:00" actually means every minute of the 03:00 hour, 60 runs. Put a specific minute first:0 3 * * *. - Steps that exceed the range.
*/90 * * * *does not mean every 90 minutes. The minute field only goes to 59, so depending on the implementation it is rejected or fires only at minute 0 of each hour. For every 90 minutes, use two schedules or a timer in your own code. Likewise*/5in the hour field is every five hours at 0, 5, 10, 15, 20, with an uneven gap at midnight. - Forgetting the environment. Cron jobs run with a minimal PATH and no shell profile. Use absolute paths and redirect output (
>> /var/log/job.log 2>&1) or failures vanish silently. - Overlapping runs. A job that takes longer than its interval will start again on top of itself. Use a lock (
flock) or the scheduler's concurrency policy. - Assuming a missed run is caught up. Classic cron does not catch up after downtime; the slot is simply gone.
- Percent signs in crontab. An unescaped
%in a crontab command is treated as a newline. Write\%, for example indate +%F.
Last, if a job triggers other systems, make the schedule the dull part: log each start, check exit codes and alert on silence, not only on errors. If you are scheduling health checks that report HTTP failures, see HTTP Status Codes Explained for what to alert on. When a string such as a log line needs parsing in the same pipeline, our Regex Tester is handy; the pitfalls are in Regex Patterns and Pitfalls.