How to read a cron expression, field by field
A cron expression is a short line of text that tells a scheduler when to run a job. The usual form has five fields separated by spaces: minute, hour, day of month, month and day of week. The line 0 9 * * 1-5 means 09:00 on Monday to Friday. Each field is a number, a name, a list, a range or a step, or * for every value, and a job runs at each time where all the fields match.
The five fields
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0 to 59 | 30 is minute 30 of the hour |
| Hour | 0 to 23 | 9 is 09:00, on a 24-hour clock |
| Day of month | 1 to 31 | 15 is the 15th |
| Month | 1 to 12, or JAN to DEC | 3 or MAR is March |
| Day of week | 0 to 6, or SUN to SAT | 0 or SUN is Sunday, 1 is Monday |
Some systems also accept 7 for Sunday, but not all do, so use 0 or SUN. Cron has no seconds field in this form, so the smallest step is one minute.
Lists, ranges, steps and names
means every value in the field.* * * *runs every minute.- A list uses commas.
0 9,17 * * *runs at 09:00 and at 17:00 every day. - A range uses a hyphen.
1-5in the day-of-week field means Monday to Friday. - A step uses a slash.
*/15in the minute field means 0, 15, 30 and 45.10-30/5means 10, 15, 20, 25 and 30. - Names such as
MON-FRIcan replace numbers. They are easier to read, if your scheduler accepts them.
These parts combine. 0 8-18/2 * * * runs at minute 0 of every second hour from 08:00 to 18:00.
Common schedules
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
/15 * * * | Every 15 minutes |
0 * * * * | At minute 0 of every hour |
0 2 * * * | Every day at 02:00 |
0 9 * * 1-5 | 09:00, Monday to Friday |
0 9,17 * * * | 09:00 and 17:00 every day |
30 6 1 * * | 06:30 on the 1st of every month |
0 0 * * 0 | Midnight every Sunday |
0 0 1 1 * | Midnight on 1 January |
/5 9-17 * 1-5 | Every 5 minutes from 09:00 to 17:55, Monday to Friday |
Note that 0 0 * * is midnight, and 0 12 * * is noon. Getting the hour wrong is one of the most common errors.
Day of month and day of week
When both the day-of-month field and the day-of-week field are restricted, the job runs when either one matches. This is the classic rule in Vixie cron and many systems derived from it. So 0 0 13 * 5 runs at midnight on the 13th of every month and also every Friday. People often expect Friday the 13th only, and get more runs than they planned.
If one of the two fields is *, only the other field counts. To run on Friday the 13th, schedule a job for each Friday and check the date inside the script. Other schedulers, including some cloud services, may use different rules, so read their documentation.
Time zones and daylight saving
Cron runs by the clock of the machine or service it runs on, which is normally that machine's local time zone. A job set for 02:30 runs at 02:30 on that clock. Check the zone first (on Linux, date shows it). If you want jobs to follow one clock everywhere, many teams run servers in UTC, and some schedulers let you set a time zone for each job.
Daylight saving changes the clock twice a year. In spring, many places jump from 02:00 straight to 03:00, so a job at 02:30 has no time to run. In autumn, the hour from 01:00 to 01:59 happens twice. Schedulers handle these cases differently. Some skip the job, some run it once, and some run it twice. Keep jobs out of the early-morning change window, or use UTC, if the difference matters to you.
Six fields and Quartz
Some schedulers add a seconds field at the start, so /10 * * * * runs every 10 seconds. The Quartz scheduler for Java uses seconds, minutes, hours, day of month, month, day of week and an optional year, and it adds four special characters:
?means "no specific value". Quartz requires it in either the day-of-month or the day-of-week field, whichever you do not set.Lmeans last.Lin the day-of-month field is the last day of the month, and6Lin the day-of-week field is the last Friday.Wmeans the nearest weekday.15Wis the weekday closest to the 15th, and it does not jump into another month.#means the nth weekday.6#3is the third Friday.
Quartz numbers the days differently from the five-field form. Its 1 is Sunday and 7 is Saturday, so Monday to Friday is 2-6, not 1-5. Always check which format your scheduler uses before you copy a line.
Common mistakes
*/7in the minute field. The values are 0, 7, 14 and so on up to 56. The next would be 63, which does not exist, so the run after 56 is at minute 0 of the next hour. The gap is only four minutes, and the spacing is uneven. Use a step that divides 60 evenly, such as 5, 10, 15 or 30.- February 30. No such date exists, so
0 0 30 2 *never runs. The same goes for the 31st in a month that has 30 days. Under the either-or rule, a day-of-week restriction can still make a run happen on other days, so check the result. - Hour 24 or minute 60. These are out of range. Most schedulers reject them when you save, but not all.
- Expecting seconds. A five-field line runs at whole minutes only.
- Confusing cron with regular expressions. In cron,
means every value. In a regular expression,means repeat the item before it. Use the regex tester for patterns, and keep cron lines separate.
Check the next runs
Before you rely on a schedule, read the line in plain words, and list its next few run times. The cron explainer does both, and that is the quickest way to catch the either-or rule or an odd step.
Quick answers
Is the first field minutes or seconds?
Minutes, in the standard five-field form. Only some six-field schedulers add seconds, and they put them first.
Why does my job run on Fridays and also on the 13th?
The day-of-month and day-of-week fields are both set, so the job runs when either one matches. Set one field to * if you want only the other.
Does cron use UTC?
Only if the machine or service is set to UTC. Otherwise it uses the local time zone of that system.
Comments
No comments yet. Be the first.


