Understanding Cron Expressions
A cron expression describes which calendar times match a schedule. It helps to translate each field independently, then compare the complete schedule with upcoming dates in the timezone where the job will actually run.
Read the expression from left to right
In a five-field crontab the fields are minute, hour, day of month, month and day of week. An asterisk means every allowed value for that field. Commas list values, a hyphen marks a range and a slash introduces a step within the field.
The first expression runs at 09:30 Monday through Friday in the scheduler’s timezone. The second matches minutes 0, 15, 30 and 45 in every hour. Neither expression describes a delay after the previous run. If a job takes 20 minutes, the second trigger may arrive while it is still running.
30 9 * * MON-FRI
*/15 * * * *Check the next runs in the actual timezone
Preview the expression with an IANA timezone such as America/New_York. For a report scheduled at 09:30 local time, the UTC equivalent changes when daylight saving time starts or ends. When your requirement is a fixed UTC time, configure UTC in the scheduler and document that choice.
A local time during a spring clock change may not exist, and a fall change can repeat an hour. Review the scheduler’s documented behavior and test across both dates. Decide separately how the job handles overlap or missed runs after downtime.
Watch for scheduler dialect differences
Some schedulers add seconds, accept names or aliases, or require a special character in one day field. An expression copied from Quartz may not fit a Unix-style scheduler. Confirm field count and timezone before deploying a converted expression.
If both the day of month and day of week are restricted, verify how your scheduler combines them. Many traditional cron implementations match either day field. That can surprise someone who expects a job to run only when both match. Compare expected calendar dates with the actual next runs.
Frequently asked questions
- How do I run twice an hour?
- Use 0,30 * * * * for the top and half of each hour.
- Where do I set the command?
- The expression is the schedule. Your scheduler or crontab entry separately determines the command, environment, user and timezone.