DEV Community

Cheng
Cheng

Posted on

Cron Syntax Explained: The 5 Fields and the Expressions You'll Actually Use (with a free generator)

Every time I need a cron expression, I stare at five numbers and asterisks and second-guess myself. Is 0 0 * * 0 Sunday or Saturday? Does day-of-week start at 0 or 1? This is the mental model that finally made it click for me.

The 5 fields, left to right

┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–6, Sunday = 0)
│ │ │ │ │
* * * * *
Enter fullscreen mode Exit fullscreen mode

* means "every". A number means "at exactly this one". That covers about 90% of what you'll write.

The four operators that handle the rest

  • * — every value (* * * * * = every minute)
  • , — a list (0 9,17 * * * = at 9:00 and 17:00)
  • - — a range (0 9-17 * * * = every hour from 9:00 to 17:00)
  • / — a step (*/15 * * * * = every 15 minutes)

The expressions you'll actually reach for

Expression When it runs
*/5 * * * * Every 5 minutes
0 * * * * Every hour, on the hour
0 0 * * * Every day at midnight
0 9 * * 1-5 9:00 AM, Monday–Friday
0 0 1 * * Midnight on the 1st of every month
0 0 * * 0 Midnight every Sunday
30 2 * * * 2:30 AM daily (handy for backups)

Two gotchas that get everyone

  1. Day-of-week is 0–6, with Sunday = 0 (most systems also take 7 for Sunday). So 0 0 * * 0 is Sunday, not Saturday.
  2. Set both day-of-month and day-of-week, and cron treats it as OR. 0 0 1 * 1 runs on the 1st of the month or any Monday — not "only when the 1st lands on a Monday". This one quietly doubles how often your job fires, and it's a pain to debug.

Don't memorize it, read it back

The fastest sanity check is to turn the expression into plain English and see if it matches what you meant. I got tired of doing that in my head, so I built a free no-login cron tool that goes both ways — describe a schedule and get the expression, or paste an expression and see the next run times: https://forgly.dev/tools/cron-generator

If you just want a copy-paste list of common schedules, there's a cheat-sheet here: https://forgly.dev/cron

The trick that stuck for me: stop reading cron right-to-left in your head and just read it as a sentence — "at minute X, hour Y, on these days."

Top comments (0)