Cron during business hours: 0 9-17 * * 1-5
0 9-17 * * 1-5 runs at the top of every hour from 09:00 through 17:00, Monday to Friday. That is nine runs a weekday and 45 a week.
At a glance
- Expression
- 0 9-17 * * 1-5
- Fires
- 9 times a weekday, 45 times a week, about 2,340 times a year.
- Restricted fields
- Minute pinned to 0, hour restricted to a range, day of week restricted to a range. Day of month and month are open.
- Equivalent macro
- None.
- Hours matched
- 9, 10, 11, 12, 13, 14, 15, 16, 17. Nine values, both ends included.
- Days matched
- Monday through Friday. MON-FRI is accepted as an alias for 1-5.
In detail
Ranges in cron are inclusive at both ends, so 9-17 is nine hours and not eight. That catches people who think of the working day as nine to five and expect the last run at 16:00. If you want the run at 17:00 to be the final one, this expression is right; if you want work to stop at 17:00, write 9-16.
The day of week field takes the same range form, and 1-5 is Monday through Friday. Because the day of month field is left as an asterisk, the special rule about day of month and day of week both being restricted does not apply here, so the weekday restriction behaves exactly as you would expect.
This expression is one of the few where an obvious variant changes the load profile a lot. Replacing the minute with */30 gives eighteen runs a weekday, and with */15 gives thirty six. Since the range and weekday parts stay identical, it is easy to tune the frequency without touching the part that encodes the business rule.
What cron cannot do is know about public holidays, and there is no field for them. A business hours job will run on every bank holiday in the year unless the script itself checks a calendar and exits early, which is usually a short list of dates in a file and a single test at the top of the script.
Examples
0 9-17 * * 1-50 9-17 * * MON-FRINames are case insensitive, so mon-fri works too.
*/30 9-17 * * 1-5 /opt/app/bin/queue-drain.sh >> /var/log/queue.log 2>&1Eighteen runs a weekday, ninety a week.
Things that catch people out
- 9-17 includes 17, so the job runs at five o'clock. Use 9-16 if the last run should be at four.
- Cron has no holiday awareness. Guard the script if running on a public holiday would be wrong.
- A range cannot wrap. 17-9 is rejected as an invalid range rather than being read as overnight.
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 →Cron every weekday: 0 0 * * 1-5
0 0 * * 1-5 runs at midnight Monday through Friday, five times a week. Day numbers, the MON-FRI alias, and why holidays still get a run.
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.
The cron hyphen: inclusive ranges and why they cannot wrap
A hyphen range includes both ends, so 9-17 is nine values. The start must not be greater than the end, which is why 22-6 is rejected.
Cron every 15 minutes on weekdays: */15 * * * 1-5
*/15 * * * 1-5 fires 96 times a weekday and 480 times a week. Combining a minute step with a weekday range, and how to add an hour window too.
Cron every minute during a single hour: * 3 * * *
* 3 * * * fires 60 times a day, once a minute for the whole of the 03:00 hour, then nothing until the next day. A useful burst pattern.
Cron at the weekend: 0 0 * * 0,6
0 0 * * 0,6 runs at midnight on Saturday and Sunday, twice a week. Why 6-7 works too, and why 6-0 is rejected as an invalid range.
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