DevRivet

Blog ·

Cron Expression for Weekdays Only (Monday to Friday)

Use 0 9 * * 1-5 or 0 9 * * MON-FRI to run a cron job Monday to Friday only. Covers day numbering, Sunday as 0 or 7, and timezone pitfalls.

Cron Expression Generator

Build, understand and validate cron expressions.

Try it free →

The cron expression for weekdays only is 1-5 in the day-of-week field, or MON-FRI. For example, 30 8 * * 1-5 runs at 8:30 AM, Monday through Friday. To build and preview these schedules, use the Cron Expression Generator.

How the day-of-week field works

A standard cron expression has five fields in this order: minute, hour, day of month, month, and day of week. Weekdays only is a restriction on the last field. The other four fields usually stay as *, which means every value.

  • Minute: 0-59
  • Hour: 0-23
  • Day of month: 1-31
  • Month: 1-12 or JAN-DEC
  • Day of week: 0-6 or SUN-SAT, where 0 is Sunday

Weekdays with numbers or names

Both forms below are usually accepted by cron implementations and cron libraries. They select the same days.

30 8 * * 1-5 /usr/local/bin/report.sh
30 8 * * MON-FRI /usr/local/bin/report.sh

A few details to know:

  • 1-5 means Monday, Tuesday, Wednesday, Thursday, Friday.
  • MON-FRI is easier to read but relies on name support. Most Vixie-style cron implementations accept it, and so do most cron libraries, but a few schedulers do not.
  • Names are case-insensitive in most implementations, but use uppercase to be safe.
  • A list such as 1,2,3,4,5 also works, but a range is shorter and clearer.

Why avoid 7 for Sunday

In standard cron, 0 is Sunday and 6 is Saturday. Many implementations also accept 7 as Sunday, but not all of them do. Because of that, avoid 7 entirely. Writing 1-5 for weekdays sidesteps the problem, since it never touches Sunday or Saturday.

If you ever need a range that includes the weekend, such as Saturday and Sunday, write 6,0 instead of 6-7.

Common weekday schedules

Here are some variants that use the same day-of-week pattern:

0 9 * * 1-5          # 9:00 AM, weekdays
0 0 * * 1-5          # midnight, weekdays
0 * * * 1-5          # top of every hour, weekdays
*/15 9-17 * * 1-5    # every 15 minutes from 9:00 to 17:45, weekdays
30 18 * * 1-5        # 6:30 PM, weekdays

For a single day, such as only Mondays, see Cron Every Monday. For daily jobs that run every day, see Cron Every Day at Midnight.

Cron has no timezone field

This is the most common mistake. Standard cron has no way to say which timezone a schedule uses. It runs against the clock of the machine where it lives. If your server is set to UTC, then 30 8 * * 1-5 means 8:30 AM UTC, not 8:30 AM in your office.

  • Check the server timezone before you set the schedule. Compare the output of date with the timezone you expect.
  • Daylight saving time changes can cause a job to skip a run or, in some implementations, run twice. A job set near 2:00 AM is the most exposed.
  • Some cron implementations support a timezone setting, such as a CRON_TZ variable in cronie. Support varies, so check your platform's documentation before relying on it.
  • Hosted schedulers have their own timezone settings. Set them explicitly rather than assuming the default.

Cloud schedulers use different syntax

Many cloud schedulers do not use the standard five-field format. AWS EventBridge, for example, uses six fields and requires one of the two day fields to be a question mark. Its day-of-week numbering can also differ, with 1 as Sunday. Check the current docs for your provider. The weekday version in EventBridge looks like this:

cron(30 8 ? * MON-FRI *)

Skipping public holidays

Cron cannot skip holidays on its own. The usual approach is to keep the weekday schedule and add a check at the start of the script. The date command's %u format returns 1 for Monday through 7 for Sunday, which is handy here.

#!/bin/bash
if [ "$(date +%u)" -gt 5 ]; then exit 0; fi
if grep -qx "$(date +%F)" /etc/holidays.txt; then exit 0; fi
/usr/local/bin/report.sh

The holidays file holds one YYYY-MM-DD date per line. This keeps the schedule simple and moves the calendar logic into code you can test.

Common mistakes

  • Restricting both day fields. In standard cron, when both day-of-month and day-of-week are restricted, the job runs when either one matches. For example, 0 9 13 * 5 runs on the 13th and on every Friday, not only on Friday the 13th. Keep day-of-month as * for weekday jobs.
  • Assuming 0 is Monday. Python's datetime.weekday() uses Monday as 0, but cron uses Sunday as 0. Mixing the two is an easy way to run a job on the wrong days.
  • Using 7 for Sunday, as noted above.
  • Expecting timezone handling from cron itself, as covered above.

Check your expression before deploying

Paste the expression into the Cron Expression Generator to see a plain-language description and the next run times. Check that the first few dates are Monday through Friday and that the time matches the timezone your server uses.

FAQ

Does 1-5 work in every cron version?

Numeric ranges are part of standard cron and work in most implementations. Name-based values such as MON-FRI are a common extension. They are widely supported, but test them on your platform if you are unsure.

How do I run a job on weekdays every hour?

Use 0 * * * 1-5. The minute field is 0, so the job runs at the top of every hour, and the day-of-week field limits it to Monday through Friday.

Can cron skip public holidays?

Not by itself. Add a check in the script that exits early on holiday dates, as shown above, or use a scheduler that supports a holiday calendar.

Cron Expression Generator

Build, understand and validate cron expressions.

Try it free →