The cron hyphen: inclusive ranges and why they cannot wrap
A hyphen creates a range that includes both endpoints, so 9-17 is nine values and not eight. The start value must be less than or equal to the end, so a range can never wrap.
At a glance
- Meaning
- Match every value from the start through to the end, inclusive.
- Count
- end minus start plus one. 9-17 is nine values.
- Direction
- Ascending only. A start greater than the end is rejected as an invalid range.
- Bounds
- Both ends must be inside the field range, or the expression is rejected.
- With names
- Allowed in the month and day of week fields, so MON-FRI and JAN-MAR both work.
- With a step
- start-end/n walks the range in increments of n, for example 0-30/10.
In detail
Ranges in cron include both endpoints, which is the opposite convention to most programming languages and the source of a persistent off by one. An hour range of 9-17 covers 09:00 through 17:00, nine separate hours, so a job described as running nine to five will have a run at five o'clock.
The range is evaluated as a simple ascending walk, so the start has to come first. 22-6 in the hour field is rejected rather than being read as an overnight window, and 6-0 in the day of week field is rejected rather than being read as the weekend. Anything that needs to cross the end of a field has to be written as two pieces joined by a comma.
Both endpoints are checked against the field bounds before anything else happens, so 0-31 in the hour field fails on the upper bound and 0-59 in the day of month field fails for the same reason. That check is why a range typo usually produces a clear message naming the field rather than a schedule that quietly does the wrong thing.
A range can carry a step, and this is the form that makes an offset schedule possible. 0-30/10 in the minute field gives 0, 10, 20 and 30, stopping at the end of the range rather than continuing to 59. Combining a range and a step is how you restrict a repeating job to part of an hour or part of a day.
Examples
0 9-17 * * *Nine runs a day, including one at 17:00.
0 0 * * MON-FRIMonday through Friday. Names are case insensitive.
0-30/10 * * * *Minutes 0, 10, 20 and 30 only. Nothing in the second half of the hour.
Things that catch people out
- 9-17 is nine hours, not eight. If work should stop at five, the range is 9-16.
- A range cannot wrap. 22-6 and 6-0 are both rejected, and the overnight or weekend case needs a comma list.
- A range with a step stops at the end of the range, not at the end of the field. 0-30/10 never reaches minute 40.
Try it: Cron Expression Parser
Paste any five or six field expression to get a plain English description, a per field breakdown and the next run times in your local time.
Cron Expression Parser
LOCAL · Browser-OnlyParse cron expressions and see the next scheduled run times
Supports 5-field (minute hour day month weekday), 6-field (with seconds), named values (JAN, MON), and @macros (@daily, @hourly, ...)
Use the dropdowns below to build your cron expression visually, or type a custom value in each field.
Human-Readable Description
Every 5 minutes
Field Breakdown
| Field | Allowed | Value | Meaning |
|---|---|---|---|
| Minute | 0-59 | */5 | every 5 minute(s) |
| Hour | 0-23 | * | every hour |
| Day of Month | 1-31 | * | every day of month |
| Month | 1-12 | * | every month |
| Day of Week | 0-7 | * | every day of week |
Related cron expressions
All cron expressions →The cron comma: listing several values in one field
A comma joins several values into one field, and each element can itself be a value, a range or a step. Spaces inside a list break the expression.
Cron step values: what */n really does
*/n walks a field from its minimum in increments of n. Because it starts at the field minimum, */2 gives even minutes and odd days of the month.
Cron overnight from 22:00 to 06:00: why 22-6 does not work
A cron range cannot wrap past midnight, so 22-6 is rejected. Split it into 22,23,0-6 to get nine hourly runs across the overnight window.
Cron name aliases: JAN to DEC and SUN to SAT
The month and day of week fields accept three letter English names, case insensitively, in single values, ranges, lists and steps.
Cron n/step: starting a step from a value you choose
The form 5/15 means start at 5 and step by 15, giving 5, 20, 35 and 50. It is how you move a repeating job off the crowded top of the hour.
The cron minute field: position, range and behaviour
The minute field runs 0 to 59 and is the first field in a five field expression, or the second when a seconds field is present.
Tools for this
- Cron Expression Parser Free online cron expression parser - parse cron expressions and see the next scheduled run times
- Crontab Generator Free online crontab generator - build cron expressions visually with an intuitive interface