Blog ·
How to Read a Cron Expression: Field-by-Field Explanation
Minute, hour, day of month, month, day of week: learn each field's range, the special characters, and how to decode any 5-field cron expression.
Cron Expression Generator
Build, understand and validate cron expressions.
A standard cron expression has five fields, separated by spaces, in this order: minute, hour, day of month, month, day of week. Each field accepts a number, a range, a list, or a wildcard, and together they define when a job runs. Read them left to right, one field at a time, and the schedule becomes clear.
If you want to build an expression instead of reading one, the Cron Expression Generator lets you pick values for each field and shows the plain-English meaning and the next run times. It is also a quick way to check your reading of an expression you did not write.
The five fields and their allowed ranges
# ┌───────────── minute (0-59) # │ ┌─────────── hour (0-23) # │ │ ┌───────── day of month (1-31) # │ │ │ ┌─────── month (1-12, or JAN-DEC) # │ │ │ │ ┌───── day of week (0-7, or SUN-SAT) # │ │ │ │ │ # * * * * *
- Minute: 0 to 59. The first field.
0means the top of the hour. - Hour: 0 to 23, using 24-hour time.
0is midnight and14is 2 PM. - Day of month: 1 to 31. Note that it starts at 1, not 0.
- Month: 1 to 12, where
1is January. Most implementations also accept the names JAN through DEC, usually case-insensitive. - Day of week: 0 to 7, where both
0and7mean Sunday. Most implementations also accept SUN through SAT. In standard cron,1is Monday, so1-5means Monday through Friday.
Ranges are inclusive. 1-5 in the day-of-week field covers five values, and 9-17 in the hour field covers 9 AM through 5 PM, including the 5 PM hour.
The special characters
Five characters cover almost every expression you will see in a standard crontab:
*means every valid value for that field. In the hour field,*means every hour.,separates a list of values.15,45means minute 15 and minute 45.-defines an inclusive range.1-6means 1, 2, 3, 4, 5 and 6./defines a step.*/15means every 15 values across the full range, so minutes 0, 15, 30 and 45.10-30/5means 10, 15, 20, 25 and 30.?is not part of standard 5-field cron. You will see it in Quartz and some other schedulers, where it means 'no specific value' for day of month or day of week. If you paste a?into a Linux crontab, it will fail. Use*instead.
The step syntax applies to the range before the slash. */2 in the hour field means hours 0, 2, 4 and so on up to 22. It does not mean every two days, and it does not reset cleanly at the end of the month. For day-based schedules, use a specific day list or a separate rule rather than a step.
How to decode an unfamiliar expression
Take this expression:
15,45 14 * 1-6 1-5
Go field by field:
- Minute
15,45: the job fires at minute 15 and minute 45 of the hour. - Hour
14: that is 2 PM in 24-hour time, so the hour is 14:00 to 14:59. - Day of month
*: any day of the month. - Month
1-6: January through June. - Day of week
1-5: Monday through Friday, using the standard convention that1is Monday.
Put together, the job runs at 14:15 and 14:45 on weekdays from January through June. Nothing runs on weekends, in July through December, or at any other time.
When you read an expression, do the minute and hour first, because they usually give you the time of day. Then check the date fields. A wildcard * in a date field is a common reason a schedule runs more often than expected.
Common expressions and what they mean
0 0 * * *: every day at midnight. See Cron Every Day at Midnight.*/5 * * * *: every 5 minutes, all day. See Cron Every 5 Minutes.0 */2 * * *: at minute 0 of every second hour, starting at midnight. See Cron Every 2 Hours.0 9 * * 1-5: 9:00 AM on Monday through Friday. See Cron Expression for Weekdays Only.0 0 1 * *: midnight on the first day of every month. See Cron Expression for First Day of the Month.
Pitfalls that catch developers
Most cron mistakes come from a few habits:
- Reading the fields in the wrong order. The minute comes first, not the hour.
0 9 * * *is 9:00 AM, while9 0 * * *is 12:09 AM. - Assuming
*/nin the day-of-month field means every n days.*/2in that field means days 1, 3, 5 and so on, which is not a fixed two-day cycle across months. - Forgetting that day of month and day of week combine. In traditional Vixie cron, and most implementations derived from it, if both fields are restricted (neither is
*), the job runs when either one matches. So0 0 13 * 5runs on every Friday and also on the 13th of every month. If you want Friday the 13th only, you need a script or a different scheduler. - Expecting seconds. A standard crontab has five fields and no seconds field. Some schedulers add a sixth field for seconds, and that changes the meaning of every other field, so check which format your tool uses.
- Ignoring the time zone. Cron usually uses the server's local time zone, not UTC. Daylight saving time changes can skip or repeat an hour. Check the server's time zone before you rely on an exact hour.
- Assuming a valid expression means the job will run. A syntactically correct expression can still fail to run if the environment is wrong. If a job silently does nothing, see Cron Job Not Running? Common Causes and Fixes.
A quick checklist for reading any expression
- Confirm there are exactly five fields. If there are six or seven, the scheduler is using a non-standard format.
- Read the minute and hour to get the time of day.
- Read the day of month and month to get the dates.
- Read the day of week, remembering that
0and7are both Sunday. - Check whether the day-of-month and day-of-week fields are both restricted. If so, remember the OR behavior in Vixie cron.
- Run the expression through the Cron Expression Generator to confirm the next run times match what you expect.
FAQ
What does the 0 in a cron expression mean?
In the minute field, 0 means the top of the hour. In the hour field, 0 means midnight. In the day-of-week field, 0 means Sunday. The meaning depends on the field the value sits in.
Is there a difference between Sunday as 0 and Sunday as 7?
In standard cron, no. Both 0 and 7 mean Sunday in the day-of-week field, and they can be used interchangeably. Other schedulers may only accept one of them, so use 0 if you want the most portable option.
Why does my job run on the 13th when I only wanted Fridays?
In Vixie cron, when both the day-of-month and day-of-week fields are restricted, the job runs when either condition is true. Set one of them to * if you want the other to apply on its own.
Can I use names like MON instead of numbers?
Usually yes. Most implementations accept three-letter names for months (JAN to DEC) and days of the week (SUN to SAT). Names are easier to read in long expressions, but check your scheduler's documentation if you are unsure.
Cron Expression Generator
Build, understand and validate cron expressions.