The Complete Guide to Cron Expressions
Everything you need to know about cron expressions, from basics to advanced scheduling across different platforms.
1. What is Cron?
Cron is a time-based job scheduler in Unix-like operating systems. Users can schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals. The name "cron" comes from the Greek word "chronos" meaning time.
A cron expression is a string that defines when a scheduled task should run. It's used not just in Unix systems, but also in many modern platforms like Kubernetes, cloud services (AWS, Azure, GCP), CI/CD pipelines (GitHub Actions, GitLab CI), and application frameworks (Spring, Quartz).
2. Cron Expression Fields
A standard Unix cron expression consists of 5 fields separated by spaces:
| Field | Allowed Values | Description |
|---|---|---|
| Minute | 0-59 | Minute of the hour |
| Hour | 0-23 | Hour of the day (24-hour format) |
| Day of Month | 1-31 | Day of the month |
| Month | 1-12 or JAN-DEC | Month of the year |
| Day of Week | 0-6 or SUN-SAT | Day of the week (0 = Sunday) |
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6)
│ │ │ │ │
* * * * *3. Special Characters
Cron expressions support several special characters to create complex schedules:
* (asterisk) — Every value. Example: * * * * * runs every minute.
, (comma) — List of values. Example: 0,15,30,45 * * * * runs at minutes 0, 15, 30, 45.
- (hyphen) — Range of values. Example: 0 9-17 * * * runs every hour from 9 AM to 5 PM.
/ (slash) — Step values. Example: */5 * * * * runs every 5 minutes.
? (question mark) — No specific value (Quartz, AWS). Used in day-of-month or day-of-week when the other field is specified.
4. Common Examples
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour at minute 0
0 0 * * *Every day at midnight
0 9 * * 1-5Every weekday at 9 AM
0 0 1 * *First day of every month at midnight
0 0 * * 0Every Sunday at midnight
5. Cron Flavors Compared
Different platforms have variations on the standard cron syntax. Here's how they compare:
| Platform | Fields | Notes |
|---|---|---|
| Unix/Linux | 5 | Standard format: min hour dom mon dow |
| Quartz | 6-7 | Adds seconds (and optional year). Uses ? character. |
| Spring | 6 | Seconds minute hour dom mon dow |
| GitHub Actions | 5 | Standard Unix format, UTC timezone |
| AWS EventBridge | 6 | Wrapped in cron(). Uses ?. |
| Azure Functions | 6 | NCRONTAB format with seconds |
Quartz Example
0 0 12 * * ? # Every day at 12:00 PMThe first 0 is seconds, ? means no specific day-of-week.
AWS EventBridge Example
cron(0 12 * * ? *) # Every day at 12:00 PM UTCNote the cron() wrapper and 6 fields with year.
Spring Example
0 0 */2 * * * # Every 2 hoursFirst field is seconds (set to 0).
GitHub Actions Example
0 9 * * 1-5 # Weekdays at 9 AM UTCStandard 5-field format. Remember: GitHub Actions always runs in UTC.
Azure Functions (NCRONTAB) Example
0 30 9 * * 1-5 # Weekdays at 9:30 AM6-field format with seconds first. Supports timezone configuration in host.json.
6. Common Pitfalls
Timezone Confusion
GitHub Actions and many cloud services run in UTC. Always verify your cron's timezone and convert from your local time.
Day-of-Month vs Day-of-Week
In Quartz/AWS, specifying both day-of-month and day-of-week can cause unexpected behavior. Use ? for the field you don't need.
Forgetting Seconds
Quartz, Spring, and Azure Functions require 6 fields. Missing the seconds field will cause parse errors.
Invalid Day-Month Combinations
Setting 0 0 31 2 * (Feb 31) will never run. Some systems silently skip; others error.
Ready to build your cron expression?
Use our visual builder to create and validate cron expressions instantly.
Try the Cron Builder