Cron expressions let you run recurring tasks without hard-coding dates into an application. This guide explains cron syntax field by field, provides practical cron job examples, and gives you a repeatable checklist for testing schedules, diagnosing incorrect run times, and avoiding time-zone and daylight-saving surprises.
Overview
A cron expression is a compact schedule made from fields such as minutes, hours, days, months, and weekdays. A traditional Unix-style cron expression normally contains five fields:
┌──────── minute (0–59)
│ ┌────── hour (0–23)
│ │ ┌──── day of month (1–31)
│ │ │ ┌── month (1–12)
│ │ │ │ ┌ day of week (0–7, depending on implementation)
│ │ │ │ │
* * * * *
The asterisk means “every allowed value.” Other operators make the schedule more precise:
- Comma: a list, such as
1,15,30. - Hyphen: a range, such as
9-17. - Slash: an interval, such as
*/15for every 15 units within the field. - Specific value: one exact value, such as
3in the hour field.
For example, 30 2 * * * means 02:30 every day in a five-field cron implementation. That interpretation is incomplete until you also know the scheduler’s time zone, whether it supports a seconds field, and how it handles daylight-saving transitions.
Traditional cron is not universal. Some systems use six fields with seconds at the beginning, while Quartz-style schedulers commonly include seconds and may use a question mark or different weekday conventions. Cloud schedulers can also use a five-field cron format but apply the expression in a configured region or UTC by default. Treat the platform’s documented grammar as the source of truth before deploying a schedule.
Checklist by scenario
Every few minutes
Use a step value when the task should repeat at regular intervals:
*/5 * * * *
This requests every five minutes in a standard five-field format. If the job can run longer than five minutes, add a concurrency safeguard so one invocation does not overlap the next.
Once per day
0 3 * * *
This runs at 03:00 each day in the scheduler’s effective time zone. For backups, reports, and cleanup jobs, confirm whether “03:00” means server time, UTC, a project time zone, or a user-selected local time.
On weekdays
0 9 * * 1-5
This commonly means 09:00 Monday through Friday. Weekday numbering varies: some implementations accept both 0 and 7 for Sunday, while others use names or a different convention. Test the expression in the actual scheduler or its documented parser.
On a particular day of the month
0 6 1 * *
This runs at 06:00 on the first day of every month. It does not automatically run on the first weekday. If a monthly task must avoid weekends, express that business rule in the job or use a scheduler feature designed for calendar-based dates.
During business hours
0 9-17 * * 1-5
This runs at the top of each hour from 09:00 through 17:00 on weekdays. The range is inclusive in common cron implementations. If you need 09:00 through 16:00 only, use 9-16 instead.
Using a cron builder or schedule generator
A cron builder can reduce syntax errors, but it should support the exact dialect used by your target platform. Enter the desired frequency, inspect the generated fields, and verify several upcoming run times. A visual explanation is especially useful when an expression contains multiple lists, ranges, or intervals.
Testing a job before deployment
- Write the requirement in plain language: “At 02:30 every day in Europe/London,” for example.
- Identify the scheduler dialect and whether it supports a time-zone declaration.
- Generate or write the expression, then manually inspect every field.
- Use a parser, cron tester, or staging scheduler to calculate upcoming occurrences.
- Test the command independently with the same environment variables, permissions, working directory, and credentials.
- Confirm logs, alerts, exit codes, and retry behavior.
- Deploy with a way to disable or roll back the schedule without changing application code.
What to double-check
Time zones and daylight saving time
The most common reason a valid cron expression appears to run at the wrong time is an unexpected time zone. A server may use UTC while a developer reads the expression as local time. A hosted scheduler may have a project-level or job-level time-zone setting. Record the intended time zone next to the expression rather than documenting only “runs at 09:00.”
Daylight-saving changes create two unusual cases: a local clock time may occur twice when clocks move backward, or it may not occur when clocks move forward. Decide whether the job should run once, twice, or be skipped in those situations. For critical billing, notification, and data-processing workflows, consider using UTC or a scheduler with explicit time-zone and calendar semantics. Make the task idempotent so a duplicate invocation is safe.
Day-of-month and day-of-week behavior
In many traditional cron implementations, when both the day-of-month and day-of-week fields contain restrictions, the scheduler treats them as an “either” condition rather than requiring both conditions at once. That means an expression intended to mean “the first Monday” may run on the first day of the month and on Mondays. Other systems, including some Quartz-style schedulers, use different rules or special syntax. Verify this behavior with the platform documentation and a set of calendar test dates.
Execution context
Cron jobs often run with a smaller environment than an interactive shell. Use absolute paths where appropriate, define required environment variables, set the working directory explicitly, and send output to a known log destination. Review secret handling with an environment variables and secrets checklist. A correct schedule cannot compensate for a command that fails because a binary or credential is unavailable.
Retries, overlap, and observability
Decide what happens if the command fails, times out, or is still running at the next scheduled time. Add a lock, queue, unique run identifier, or idempotency key when overlapping executions could duplicate work. Record the scheduled time, actual start time, duration, result, and error output. For jobs that call an API, define retry limits and backoff using an API error-handling and retry strategy.
Common mistakes
- Reversing minutes and hours:
0 8 * * *is usually 08:00, while8 0 * * *is usually 00:08. - Assuming all cron formats match: a six-field expression may include seconds, but five-field cron usually does not.
- Using an unsupported symbol: special characters accepted by one scheduler may be rejected by another.
- Forgetting inclusive ranges:
9-17generally includes both 09:00 and 17:00. - Assuming a failed run will retry: cron triggers a command; retry and alert policies must be configured separately.
- Ignoring missed executions: some schedulers catch up after downtime, while others simply wait for the next occurrence.
- Testing only the expression: validate the complete command, permissions, dependencies, output, and failure path.
- Hard-coding a local time without a time zone: this makes seasonal clock changes and server migrations harder to reason about.
For debugging, first separate schedule problems from application problems. Ask whether the scheduler triggered the job, whether the process started, and whether the process completed successfully. This same staged approach is useful in a broader debugging workflow: observe the failure, isolate one variable, reproduce it, and then verify the fix.
When to revisit
Revisit a cron expression whenever the job, platform, or calendar assumptions change. Add it to deployment reviews when moving from a local machine to a container, server, or cloud scheduler. Recheck it before seasonal planning cycles, especially for reports, maintenance windows, and customer notifications tied to local business hours.
Use this practical pre-deployment checklist:
- Write the schedule in plain language, including the intended time zone.
- Confirm the scheduler’s field count, allowed operators, weekday numbering, and day-of-month/day-of-week rules.
- Generate at least five upcoming run times, including a month boundary and a daylight-saving transition when relevant.
- Run the command manually in a staging environment with production-like permissions and configuration.
- Test failure, timeout, retry, duplicate, and missed-run behavior.
- Document ownership, logs, alerts, and the fastest safe way to pause the job.
- Recheck the schedule after changing infrastructure, region, container image, or scheduler settings.
A cron expression is small, but its operational meaning depends on the system around it. Treat the expression, time zone, command, and failure policy as one tested unit. That habit makes recurring automation easier to review, safer to change, and less likely to surprise you at the wrong hour.