How to Build Cron Expressions — A Visual Guide
Learning how to build cron expressions is an essential skill for developers, system administrators, and anyone who needs to automate scheduled tasks. Cron is the time-based job scheduler used in Unix-like systems, and its expression syntax is used by countless tools, frameworks, and cloud platforms.
In this visual guide, we'll break down cron expression syntax into digestible pieces, show you common patterns, and introduce you to tools that make building cron expressions effortless. By the end, you'll be scheduling tasks like a pro.
What Is a Cron Expression?
A cron expression is a string consisting of five (or six) fields separated by spaces. Each field represents a unit of time, and together they define when a scheduled task should run.
* * * * * = Every minute of every hour of every day
The five standard fields are:
- Minute (0-59) — Which minute of the hour
- Hour (0-23) — Which hour of the day (24-hour format)
- Day of Month (1-31) — Which day of the month
- Month (1-12 or JAN-DEC) — Which month
- Day of Week (0-7 or SUN-SAT) — Which day of the week (0 and 7 are both Sunday)
Some implementations add a sixth field for seconds (at the beginning) or year (at the end), but the five-field format is most common.
Understanding Special Characters
Cron expressions use special characters to create flexible schedules. Mastering these is key to building effective cron jobs.
Asterisk (*) — Any Value
The asterisk matches any value for that field. * * * * * runs every minute because every field accepts any value.
Comma (,) — List of Values
Specify multiple values. 0 8,12,17 * * * runs at 8:00 AM, 12:00 PM, and 5:00 PM.
Hyphen (-) — Range of Values
Define a range. 0 9-17 * * * runs every hour from 9:00 AM to 5:00 PM.
Slash (/) — Step Values
Run at intervals. */15 * * * * runs every 15 minutes. 0 */2 * * * runs every 2 hours.
Question Mark (?) — No Specific Value
Used in some systems (like Quartz) for the day-of-month or day-of-week fields when you don't care about that field.
Common Cron Expression Examples
Here are the most frequently used cron patterns that you'll encounter:
| Expression | Description | Use Case |
|---|---|---|
* * * * * |
Every minute | Health checks, real-time monitoring |
*/5 * * * * |
Every 5 minutes | Data sync, cache updates |
0 * * * * |
Every hour (at minute 0) | Hourly reports, log rotation |
0 0 * * * |
Daily at midnight | Backups, daily reports |
0 9 * * 1-5 |
Weekdays at 9 AM | Business hours start |
0 0 * * 0 |
Every Sunday at midnight | Weekly maintenance |
0 0 1 * * |
First of every month | Monthly reports, billing |
0 0 1 1 * |
January 1st at midnight | Yearly tasks |
30 4 * * * |
Daily at 4:30 AM | Low-traffic maintenance window |
0 */4 * * * |
Every 4 hours | Periodic data processing |
⏰ Build Cron Expressions Visually
Stop guessing at cron syntax. CronForge lets you build expressions with dropdowns and shows exactly when your job will run.
Try CronForge Free →Building Complex Expressions
Real-world scheduling often requires combining multiple patterns. Let's walk through some scenarios:
Run at Multiple Specific Times
To run a job at 9 AM, 1 PM, and 5 PM on weekdays:
0 9,13,17 * * 1-5
This breaks down as: minute 0, hours 9/13/17, any day of month, any month, Monday through Friday.
Run During Business Hours Only
Every 30 minutes between 9 AM and 6 PM, Monday to Friday:
*/30 9-18 * * 1-5
Run on the 15th and Last Day of Month
Payroll processing twice a month:
0 9 15,L * *
Note: The L (last day) is supported in some cron implementations like Quartz, not standard Unix cron.
Run Every Weekday Except Wednesday
0 9 * * 1,2,4,5
Explicitly list the days: Monday, Tuesday, Thursday, Friday.
Time Zones and Cron
One of the trickiest aspects of cron is handling time zones. By default, cron uses the system's local time. This can cause issues when:
- Your server is in a different time zone than your users
- Daylight saving time changes occur
- You're running jobs in cloud environments with UTC defaults
Best Practice: Use UTC for all cron jobs and convert times as needed. Most cloud platforms (AWS, GCP, Azure) default to UTC.
If you need a job at 9 AM Eastern (UTC-5), schedule it for 2 PM UTC:
0 14 * * *
During daylight saving time (UTC-4), you'd need to adjust to 1 PM UTC. This is why many teams use scheduling services that handle time zone conversions automatically.
Visual Cron Building Tools
Writing cron expressions by hand is error-prone. Visual builders eliminate guesswork and show you exactly when your schedule will trigger.
CronForge — Our Recommendation
CronForge is a free, browser-based cron expression builder that makes scheduling intuitive:
- Visual interface — Select values from dropdowns instead of memorizing syntax
- Plain English descriptions — See "Every day at 9:00 AM" instead of cryptic expressions
- Next run preview — Shows the next 5-10 scheduled executions
- Copy to clipboard — One-click copying for your crontab or config files
- No account required — Works entirely in your browser
When you're new to cron or building complex schedules, a visual tool saves hours of debugging and prevents costly mistakes like accidentally running a heavy job every minute instead of every hour.
Common Cron Mistakes to Avoid
Even experienced developers make these errors. Watch out for:
1. Forgetting That Day of Week Starts at 0 or 1
Different systems use different conventions. In standard cron, 0 and 7 both represent Sunday. Some systems use 1-7 (Monday-Sunday). Always verify your system's convention.
2. Mixing Day of Month and Day of Week
0 9 15 * 1 means "9 AM on the 15th AND every Monday" in standard cron, not "9 AM on the 15th IF it's a Monday." The two fields are OR'd, not AND'd.
3. Step Values Starting Point
*/15 * * * * runs at :00, :15, :30, :45 — not starting from when you deployed. The first run might be immediate if you deploy at :14.
4. Overlapping Schedules
Multiple cron jobs triggering simultaneously can overwhelm resources. Stagger start times: 0 3 * * *, 10 3 * * *, 20 3 * * *.
5. Not Handling Job Duration
If a job takes 10 minutes but runs every 5 minutes, you'll have overlapping executions. Use locking mechanisms or extend the interval.
Testing Your Cron Expressions
Before deploying a cron job to production, always test your expression:
- Use a visual builder like CronForge to verify the schedule
- Check next execution times — does the schedule match your expectations?
- Consider edge cases — month boundaries, leap years, daylight saving transitions
- Start with logging — have the job log its execution before doing real work
- Monitor initial runs — watch the first few executions to confirm timing
Cron in Different Platforms
While the core syntax is similar, different platforms have variations:
Linux/Unix Crontab
The original. Five fields, managed with crontab -e. Limited to the user's permissions.
AWS CloudWatch Events / EventBridge
Uses cron() or rate() expressions. Six fields (adds seconds). Supports wildcards but not all special characters.
GitHub Actions
Uses standard five-field syntax in .github/workflows/*.yml. UTC time zone only.
Kubernetes CronJobs
Standard five-field cron. Time zone depends on the kube-controller-manager configuration.
Node.js (node-cron, cron)
Six fields with seconds. Some libraries support extended syntax.
Frequently Asked Questions
What is a cron expression?
A cron expression is a string of five or six fields separated by spaces that defines a schedule for running automated tasks. The fields represent: minute, hour, day of month, month, day of week, and optionally seconds or year.
How do I run a cron job every 5 minutes?
Use the expression */5 * * * * — the */5 in the minute field means "every 5 minutes", and the asterisks mean "any value" for the other fields.
What's the easiest way to build cron expressions?
Use a visual cron builder like CronForge. It lets you build expressions by selecting options from dropdowns and shows you in plain English when your job will run.
Why isn't my cron job running at the expected time?
Common causes: wrong time zone (cron typically uses system time), syntax errors in the expression, or the job overlapping with a previous run. Use a cron validator to check your expression.
What's the difference between 0 0 * * * and @daily?
They're equivalent — both run once daily at midnight. The @daily shorthand (and others like @hourly, @weekly) is supported by some cron implementations for readability.
Conclusion
Building cron expressions becomes intuitive once you understand the five-field structure and special characters. Start with simple schedules, test thoroughly, and use visual tools like CronForge when building complex patterns.
Remember: cron runs in the system's time zone, edge cases exist around month boundaries, and testing is essential before production deployment. With these fundamentals, you're ready to automate any scheduling requirement.
Ready to Build Your Schedule?
Create cron expressions visually with instant feedback on when your jobs will run.
Try CronForge Free →