Cron: Every 15 Minutes, 9am-5pm, Weekdays
To run a cron job every 15 minutes only during business hours, use */15 9-17 * * 1-5. The step */15 fires at :00, :15, :30 and :45, the hour range 9-17 limits it to 9am through 5pm, and 1-5 keeps it on weekdays.
The expression
*/15 9-17 * * 1-5 runs every 15 minutes during business hours. Copy it straight into your crontab with crontab -e.
Stacking a step, a range and weekdays
*/15 9-17 * * 1-5 means: every 15 minutes, but only in hours 9 to 17, and only Monday-Friday. The last run of the day is 17:45. Use 9-16 if you want it to stop at 16:45.
Why 1-5 means Monday to Friday
The fifth field is day-of-week: 0 (or 7) is Sunday, 1 is Monday, up to 6 Saturday. The range 1-5 is Monday through Friday, so the job skips weekends automatically.
FAQ
What is the cron expression to run every 15 minutes during business hours?
*/15 9-17 * * 1-5 — read it field by field: minute, hour, day-of-month, month, day-of-week.
How do I limit a cron job to Monday-Friday?
Set the fifth field (day-of-week) to 1-5. 0 and 7 are Sunday, 6 is Saturday, so 1-5 is Monday through Friday and weekends are skipped.
Does cron count hours in 24-hour time?
Yes. The hour field is 0-23, where 0 is midnight, 12 is noon and 17 is 5 PM. There is no AM/PM in cron.