Cron Expressions: The 5-Field Puzzle

Cron Expressions: The 5-Field Puzzle

0 9 * * 1-5 looks like a typo but means “every weekday at 9 AM.” That’s a cron expression — the standard way servers, CI systems, and task schedulers describe recurring jobs.

The five fields

minute hour day-of-month month day-of-week
Field Range Example
Minute 0–59 0 = on the hour
Hour 0–23 9 = 9 AM
Day of month 1–31 * = every day
Month 1–12 * = every month
Day of week 0–7 (0 and 7 = Sunday) 1-5 = Mon–Fri

The special characters

  • * — every value
  • */15 — every 15th value (“every 15 minutes”)
  • 1-5 — a range
  • 1,15 — a list
  • ? — “no specific value” (used when day-of-month and day-of-week conflict)

The examples you’ll actually use

Expression Meaning
0 9 * * * Daily at 9:00 AM
*/5 * * * * Every 5 minutes
0 0 1 * * Midnight on the 1st of each month
0 9 * * 1-5 Weekdays at 9:00 AM
30 3 * * 0 Sundays at 3:30 AM

The classic mistake

Day-of-month vs day-of-week: when both fields have values, most cron implementations run the job when either matches — 0 0 1 * 1 runs on the 1st and every Monday, not just “the 1st if it’s a Monday.” That surprising OR-behavior has caused real incidents. When in doubt, use ? in one of the two fields.

Writing one

The cron expression generator builds expressions from simple selections — no memorizing field order. It’s also the fastest way to decode an expression someone else wrote: the human-readable description updates as you type.

Cron is forty years old and still the scheduling standard. Learn the five fields once and you can read every scheduler’s config on earth.