Cron expressions explained: fields, examples and pitfalls
A cron expression is five fields, minute, hour, day of month, month and day of week, each describing a set of allowed values. A job runs when the current time matches all of them, with one notable exception for the two day fields.
ConvertBoxPublished
The five fields, left to right
A classic cron expression has five fields separated by spaces. Cron wakes once a minute and runs the job if the current minute, hour, day and month are each in the set that the corresponding field describes. The expression is a filter on the clock, not an interval timer, and that distinction explains most of the surprises further down.
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0-59 | 30 means at minute 30 |
| Hour | 0-23 | 0 is midnight, 13 is 1 pm |
| Day of month | 1-31 | 15 means the 15th |
| Month | 1-12 or JAN-DEC | 7 or JUL |
| Day of week | 0-6 or SUN-SAT | 0 is Sunday; most implementations also accept 7 |
Four special characters: * , - /
Each field holds a single number or a set built with four operators. They can be combined, as in 0-30/10 or 1,15,20-25.
| Character | Meaning | Example in the minute field | Fires at minutes |
|---|---|---|---|
| * | Every value | * | 0, 1, 2 ... 59 |
| , | List | 5,35 | 5 and 35 |
| - | Inclusive range | 10-13 | 10, 11, 12, 13 |
| / | Step through the range | */15 | 0, 15, 30, 45 |
| - with / | Step inside a range | 0-30/10 | 0, 10, 20, 30 |
Worked examples, read field by field
Read each expression from the minute to the weekday. A common first mistake is leaving the minute as *: the expression * 9 * * * runs sixty times, once every minute from 09:00 to 09:59.
- 0 9 * * 1-5: at 09:00, Monday to Friday.
- */15 9-17 * * 1-5: every 15 minutes during hours 9 to 17 on weekdays. The hour range is inclusive, so the last run is 17:45, not 17:00.
- 0 */6 * * *: at 00:00, 06:00, 12:00 and 18:00 every day.
- 5,35 * * * *: twice an hour, at minutes 5 and 35.
- 30 2 1 * *: at 02:30 on the first day of every month.
- 0 22 * * 0: at 22:00 every Sunday.
- 0 0 1 1 *: once a year, at midnight on 1 January.
Why */7 and the 31st behave unexpectedly
A step does not mean every N units of elapsed time. It selects values from the field's range starting at the lowest, and the selection starts over when the field wraps. In the minute field */7 matches 0, 7, 14 and so on up to 56, then 0 again, leaving a 4-minute gap at the top of each hour. In the hour field */5 matches 0, 5, 10, 15 and 20, so the gap across midnight is 4 hours. In the day-of-month field */2 matches the odd days, so the job runs on the 31st and again on the 1st. Only steps that divide the range evenly, such as 5, 10, 15, 20 or 30 for minutes and 2, 3, 4, 6, 8 or 12 for hours, give uniform spacing.
Days that do not exist are simply never matched. 0 0 31 * * runs in the seven months that have 31 days and silently skips the other five; the 30th skips February, and the 29th runs in February only in leap years. Standard cron has no symbol for the last day of the month. The usual workaround is to schedule the job on days 28-31 and have the command check whether tomorrow is the 1st before doing any work.
Day of month and day of week are joined by OR
Every field must match, with one exception. When both the day-of-month and the day-of-week fields are restricted, meaning neither is *, classic cron runs the job when either one matches. 0 0 13 * 5 is not Friday the 13th: it runs on the 13th of every month and also on every Friday. Likewise 0 9 1-7 * 1 does not mean the first Monday; it runs on each of the first seven days and on every Monday.
When one of the two fields is *, only the other restricts the schedule, which is the behaviour most people expect. For a true combination, restrict one field in the expression and test the other in the command: schedule 0 9 1-7 * * and let the script exit unless today is Monday. Schedulers with extended syntax solve this directly; in Quartz, MON#1 in the day-of-week field means the first Monday of the month.
Time zones and daylight saving time
An expression contains no time zone; the system that runs it supplies one. A traditional Linux crontab uses the server's local time. GitHub Actions schedules are always UTC. A Kubernetes CronJob uses the zone of the cluster's controller unless spec.timeZone is set. On a UTC system, a job meant for 09:00 in New York must be written with hour 14 in winter and hour 13 in summer, because the offset changes from 5 hours to 4.
Daylight saving time adds two hazards in zones that observe it. On the spring change one hour does not exist, so a job scheduled inside it may not run that day; on the autumn change one hour happens twice, so a job inside it may run twice. How a scheduler handles these cases depends on the implementation. Scheduling in UTC, or keeping jobs out of the changeover hours in local time, avoids both.
Classic cron, Quartz and platform dialects
Cron syntax is a family, not one standard. A five-field expression is not valid in Quartz, and a Quartz expression is not valid in a crontab, so check which dialect a platform expects before copying a schedule from somewhere else.
The site's cron helper parses the five standard fields. It turns the expression into a sentence in the page language and, separately, lists the next five run times in your browser's time zone; when the sentence and the dates both match your intent, the expression is right for a five-field scheduler running in that zone. Extensions such as L, W, # and ? belong to the platforms in the table, so consult their documentation. A regular expression can confirm that a string has five space-separated fields, which is useful for input validation and easy to try in a regex tester, but it cannot tell you when the job will run.
| Dialect | Fields | Differences to know |
|---|---|---|
| Unix crontab | 5 | Server local time; many implementations accept shortcuts such as @daily and @hourly |
| Quartz | 6 or 7 | Seconds first, optional year last; ? required in one of the two day fields; adds L, W and # |
| Spring @Scheduled | 6 | Seconds first, no year field |
| AWS EventBridge | 6 | Minute first, year last, no seconds; ? required in one of the two day fields |
| GitHub Actions | 5 | Always UTC; shortest interval is every 5 minutes; runs can start late under load |
| Kubernetes CronJob | 5 | Controller's time zone unless spec.timeZone is set |