Invalid cron expression: what is wrong and how to fix it

A cron expression is a fixed number of space-separated fields, each with an allowed range: classic cron has five (minute, hour, day of month, month, day of week), while Quartz and Spring add seconds and sometimes a year. The scheduler rejected a field whose value is out of range, a field count it does not support, or a combination its dialect forbids. PasteKit validates each field and describes the schedule in plain English once it is valid.

Seen as:

  • "/tmp/crontab.Xq3T9a/crontab":4: bad hour errors in crontab file, can't install.
  • Cron expression must consist of 6 fields (found 5 in "30 24 * * MON-FRI")
  • Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
  • Constraint error, got value 24 expected range 0-23
  • Hour value 24 is out of range 0–23

Input

Settings

History

Load from URL

Common causes

1. A value outside the field's range

Hours run 0–23 and minutes 0–59, so midnight is hour 0, not 24. Days of the month start at 1, and in classic cron the day of week is 0–7, where both 0 and 7 mean Sunday.

Before
30 24 * * MON-FRI
After
30 0 * * MON-FRI

2. Five fields where six are expected (or the reverse)

Spring’s @Scheduled and Quartz start with a seconds field, so a crontab expression is one field short there. Pasting a Quartz expression into crontab gives one field too many. Add or remove the seconds field.

Before
*/5 * * * *
After
0 */5 * * * *

3. Quartz needs ? in one of the day fields

Quartz does not let you constrain both day of month and day of week; one of them must be ? (“no specific value”).

Before
0 0 9 * * MON-FRI
After
0 0 9 ? * MON-FRI

4. A step of zero or a schedule that never fires

*/0 is meaningless and rejected. A date that does not exist, such as 31 February, is valid syntax in some tools but never runs; PasteKit flags it.

Before
0 0 31 2 *
After
0 0 28 2 *

Frequently asked questions

What happens when I set both day of month and day of week in crontab?

Classic cron runs the job when either field matches, not both. “0 9 1 * MON” runs on the 1st of every month and on every Monday, which surprises many people.

Which time zone does a cron expression use?

The scheduler’s: the server’s local time for crontab, UTC for most cloud schedulers unless configured otherwise. Daylight-saving changes can skip or repeat jobs scheduled between 1 and 3 a.m.

Are names like MON and JAN allowed?

Yes, in the day-of-week and month fields, case-insensitively, in nearly every implementation. Ranges of names such as MON-FRI are allowed too; lists of names work in most but not all tools.

Related