A cron expression turns a recurring task into a precise schedule, but small differences in field order, time zones, and scheduler syntax can produce unexpected results. This guide explains how to read cron syntax, build expressions for common jobs, test them safely, and review them when your platform or workflow changes.
Overview
A traditional Unix-style cron expression uses five fields, read from left to right:
| Field | Allowed values | Meaning |
|---|---|---|
| Minute | 0–59 | Minute of the hour |
| Hour | 0–23 | Hour in 24-hour time |
| Day of month | 1–31 | Calendar day |
| Month | 1–12 | Month of the year |
| Day of week | 0–7 | Day of week; 0 and 7 commonly represent Sunday |
The basic symbols are enough for most schedules:
- * means every permitted value. In the minute field,
*means every minute. - , separates specific values, such as
1,15for the first and fifteenth. - - defines a range, such as
9-17for hours from 9 through 17. - / defines a step, such as
*/15for every 15 units within the field.
Read an expression by asking what each field permits. For example, 30 2 * * * means “at 02:30, every day,” assuming the scheduler uses the expected five-field format and time zone. The expression does not describe the command, its timeout, retries, or whether a previous run must finish first. Those behaviors belong to the job runner or surrounding automation.
Before using a cron builder or copying an example, check the scheduler's required format. Some tools add a seconds field, use a named time zone, or provide special syntax for intervals and calendar events. A five-field expression is not automatically portable to every CI service, hosting platform, container scheduler, or application library.
Checklist by scenario
Run every hour
To run at the start of every hour, use:
0 * * * *
To run every 20 minutes, use:
*/20 * * * *
These are different schedules. The first runs at minute zero only; the second runs at minutes 0, 20, and 40 of each hour. If the task is resource-intensive, confirm that this frequency is appropriate and that overlapping runs are handled.
Run once each day
For a daily job at 03:15:
15 3 * * *
For a daily job at 18:00:
0 18 * * *
Use the 24-hour clock. A schedule for midnight is normally written as 0 0 * * *, not with a 24 in the hour field.
Run on weekdays
A common weekday schedule is:
0 9 * * 1-5
This requests 09:00 on Monday through Friday when the scheduler maps 1–5 to those days. If your platform uses a different day numbering convention, verify it before deployment. Named weekdays may be supported, but numeric values are not universally interpreted in exactly the same way.
Run weekly
To run at 04:00 on Sunday using a commonly accepted Sunday value:
0 4 * * 0
To run at 04:00 on Monday:
0 4 * * 1
Weekly schedules are especially worth checking against the server's time zone. A job intended for a team's local Monday may run on a different calendar day when the scheduler uses UTC.
Run monthly
For the first day of every month at 01:30:
30 1 1 * *
For the fifteenth day of every month at 12:00:
0 12 15 * *
A schedule such as 0 0 31 * * does not mean “the last day of every month.” It requests the 31st, so months without a 31st will not match in many cron implementations. If you need the last calendar day, use a platform feature designed for that purpose or schedule a more frequent check that confirms the date before acting.
Combine several times
To run at 06:00, 12:00, and 18:00 each day:
0 6,12,18 * * *
To run at the start of every hour during a defined window, such as 09:00 through 17:00:
0 9-17 * * *
When building an expression, write the requirement in plain language first: “at minute zero, during hours 9 through 17, every day.” Then translate one field at a time. This makes reviews easier than starting with symbols and guessing what they mean.
Attach the expression to a safe job definition
A valid schedule is only one part of a reliable task. Record the command, working directory, environment variables, output destination, expected duration, and failure notification alongside the expression. For configuration-heavy workflows, review the file with a YAML validator before committing it; the YAML validators and formatters guide covers common CI and deployment configuration checks.
What to double-check
Field count and platform syntax
Confirm whether the scheduler expects five fields, six fields including seconds, or a platform-specific format. Also check support for ranges, step values, month and weekday names, special operators, and a time-zone declaration. Do not assume that an expression accepted by a local cron utility will behave identically in a hosted scheduler.
Time zone and daylight-saving changes
Identify the time zone used by the scheduler rather than relying on the time zone displayed on your laptop. A job set for 09:00 UTC will not remain at 09:00 in every local time zone. If the requirement is tied to a business location, document that location and configure the scheduler accordingly when the platform supports it.
Daylight-saving transitions create two edge cases. A local time may occur twice when clocks move backward, or may not occur at all when clocks move forward. The scheduler may skip, repeat, or otherwise handle that occurrence according to its implementation. Test important jobs around both transitions, and avoid scheduling critical work at an ambiguous local time when a stable UTC schedule is acceptable.
Day-of-month and day-of-week combinations
An expression that specifies both a day of month and a day of week can be misunderstood. In several traditional cron implementations, when both fields contain restrictions, a match in either field may trigger the job rather than requiring both conditions simultaneously. Other schedulers may document different behavior. If you mean “the first Monday,” look for a scheduler feature that explicitly supports ordinal calendar rules, or use a broader schedule with a date check in the command.
Overlap, retries, and missed runs
Ask what happens if a job takes longer than the interval between starts. Without a lock, queue, or platform setting, two copies may run at once. That can duplicate notifications, corrupt temporary files, or process the same records twice. Design the task to be idempotent where possible, set an appropriate timeout, and decide whether missed executions should be skipped, caught up, or retried.
Test the complete workflow, not only the expression. A cron builder can confirm that the schedule parses and identify matching dates, but it cannot prove that credentials, paths, permissions, network access, or application-level locking are correct.
Common mistakes
- Confusing minute and hour order: Cron begins with minute, then hour.
5 6 * * *means 06:05, not 05:06. - Using local time without documenting it: A server, container, CI runner, and developer workstation may use different time zones.
- Assuming “every five hours” is the same as “five times per day”:
*/5in the hour field means hours divisible by five within the scheduler's day, not a rolling five-hour interval. - Scheduling the 31st for every month: Shorter months require a separate last-day strategy.
- Forgetting the command environment: Cron jobs may have a different PATH, shell, working directory, and set of environment variables than an interactive terminal.
- Testing only the happy path: Include month boundaries, leap-day behavior when relevant, daylight-saving transitions, failed commands, and a job that runs longer than expected.
- Ignoring output: Send logs to a known destination and make failures visible. A schedule that runs silently is difficult to audit.
Keep the expression and its plain-language explanation together in version control. For example: 15 3 * * * — “run the database export daily at 03:15 in the scheduler's configured time zone.” This small note prevents later edits from changing the meaning by accident.
When to revisit
Review scheduled jobs before seasonal planning cycles, especially when a team changes operating hours, reporting deadlines, backup windows, or maintenance periods. Recheck time-zone assumptions before and after daylight-saving transitions if the job uses local time.
Revisit the expression whenever the workflow, hosting platform, CI provider, container image, command path, or deployment configuration changes. A platform migration can alter field count, default time zone, missed-run behavior, or support for special syntax even when the visible expression remains unchanged.
Use this practical review sequence:
- Write the desired schedule in plain language, including the time zone.
- Confirm the scheduler's field order and supported syntax.
- Generate or edit the expression with a cron builder, then inspect several upcoming matching times.
- Test boundary cases such as midnight, month-end, weekday changes, and daylight-saving transitions.
- Run the command in the same environment used by the scheduler.
- Check locking, retries, timeouts, logging, permissions, and alerting.
- Document the expression, owner, purpose, and next review trigger.
For related automation hygiene, pair the schedule review with pre-commit checks for formatting, tests, and secrets using the pre-commit tools guide. Treat a cron expression as production configuration: small, readable, tested, and reviewed whenever its surrounding system changes.