The cron hour field: 0 to 23 on a 24 hour clock
The hour field accepts 0 through 23 on a 24 hour clock. Midnight is 0 and midday is 12, with no AM or PM suffix available.
At a glance
- Range
- 0 to 23.
- Position
- Second of five fields, or third of six.
- Midnight
- 0. There is no hour 24.
- Midday
- 12.
- Five in the afternoon
- 17. Writing 5 gives five in the morning.
- Divisors of 24
- 1, 2, 3, 4, 6, 8 and 12 step evenly across the midnight boundary.
In detail
Cron thinks entirely in a 24 hour clock. The hour field is an integer from 0 to 23 and there is no notation for AM or PM, so every afternoon time has to be converted before it goes in the crontab. The absence of a suffix means a wrong hour is a valid expression, which is why this field produces more silent bugs than any other.
Midnight is 0 and noon is 12. That is the inverse of the twelve hour clock convention where midnight is written 12 AM, and the confusion produces a specific recurring bug: a job meant for midday scheduled at hour 0 and running twelve hours early every day for months before anybody notices.
Hour 24 does not exist. An expression using it is rejected as out of range rather than being treated as the end of the day, which is at least a loud failure. The end of a day in cron is 23:59, and a job meant to run at the very end of a day is usually written as 59 23 * * *.
Because the hour field is matched against local wall clock time, it is the field that daylight saving affects. In a zone that observes it, one hour a year does not exist and one hour a year happens twice, so an hour pinned schedule can be skipped or repeated. Running the daemon in UTC removes the question entirely.
Examples
0 17 * * *17:00. Hour 5 would be five in the morning.
59 23 * * *23:59, because there is no hour 24.
0 */6 * * *00:00, 06:00, 12:00 and 18:00.
Things that catch people out
- 0 is midnight and 12 is noon, which is the reverse of the 12 AM convention.
- 24 is out of range. There is no way to express the end of a day as hour 24.
- The hour is matched against the daemon timezone, which on a default container image is UTC rather than your local time.
Try it: Cron Expression Parser
Paste any five or six field expression to get a plain English description, a per field breakdown and the next run times in your local time.
Cron Expression Parser
LOCAL · Browser-OnlyParse cron expressions and see the next scheduled run times
Supports 5-field (minute hour day month weekday), 6-field (with seconds), named values (JAN, MON), and @macros (@daily, @hourly, ...)
Use the dropdowns below to build your cron expression visually, or type a custom value in each field.
Human-Readable Description
Every 5 minutes
Field Breakdown
| Field | Allowed | Value | Meaning |
|---|---|---|---|
| Minute | 0-59 | */5 | every 5 minute(s) |
| Hour | 0-23 | * | every hour |
| Day of Month | 1-31 | * | every day of month |
| Month | 1-12 | * | every month |
| Day of Week | 0-7 | * | every day of week |
Related cron expressions
All cron expressions →The cron minute field: position, range and behaviour
The minute field runs 0 to 59 and is the first field in a five field expression, or the second when a seconds field is present.
Cron every day at noon: 0 12 * * *
0 12 * * * runs once a day at midday. Cron has no AM or PM, so noon is hour 12 and midnight is hour 0, which is the pair people mix up.
Cron every day at 2 AM: 0 2 * * * and daylight saving
0 2 * * * runs once a day at 02:00, the hour many timezones use for daylight saving transitions. What happens when 02:00 is skipped or repeated.
Cron step values: what */n really does
*/n walks a field from its minimum in increments of n. Because it starts at the field minimum, */2 gives even minutes and odd days of the month.
The cron day of month field: 1 to 31 and missing dates
The day of month field runs 1 to 31, and a date that does not exist in a given month simply never matches. Steps start at 1, giving odd days.
The cron month field: 1 to 12 with JAN to DEC aliases
The month field runs 1 to 12 and also accepts the three letter names JAN through DEC, case insensitively, including inside ranges and steps.
Tools for this
- Cron Expression Parser Free online cron expression parser - parse cron expressions and see the next scheduled run times
- Crontab Generator Free online crontab generator - build cron expressions visually with an intuitive interface