Cron Expressions Explained: Syntax, Examples & Cheat Sheet

What is a cron expression?
A cron expression is a string of five (and sometimes six or seven) fields separated by spaces that represents a set of times. It is used primarily by the cron daemon on Unix-like operating systems to schedule jobs (commands or scripts) to run automatically at specified intervals.
While the syntax looks like cryptic gibberish at first glance—something like 0 2 * * 1-5—it is actually a highly logical and efficient way to define complex schedules. Whether you are scheduling database backups, sending automated marketing emails, or clearing server caches, understanding cron syntax is a fundamental skill for developers and system administrators.
The basic syntax: the five fields
A standard cron expression consists of five fields, representing different units of time, from minutes up to the day of the week.
* * * * *
| | | | |
| | | | +----- Day of the week (0 - 7) (Sunday=0 or 7)
| | | +------- Month (1 - 12)
| | +--------- Day of the month (1 - 31)
| +----------- Hour (0 - 23)
+------------- Minute (0 - 59)
Special characters
The true power of cron expressions lies in the special characters that allow you to define ranges and intervals within those five fields.
| Character | Meaning | Example | Explanation |
|---|---|---|---|
* | Any value | * * * * * | Runs every minute, every hour, every day. |
, | Value list separator | 0 8,15 * * * | Runs at hour 8 and hour 15 (8:00 AM and 3:00 PM). |
- | Range of values | 0 9-17 * * * | Runs every hour between 9:00 AM and 5:00 PM. |
/ | Step values | */15 * * * * | Runs every 15 minutes. |
Note: Some extended cron implementations (like AWS EventBridge or Quartz scheduler) support a 6th field for Seconds and a 7th for Year, as well as characters like ? (no specific value), L (last day of month), and W (nearest weekday).
Common cron expression examples
Here are some of the most common scheduling requirements and their corresponding cron expressions.
High frequency
- Every minute:
* * * * * - Every 5 minutes:
*/5 * * * * - Every 15 minutes:
*/15 * * * * - Every 30 minutes:
0,30 * * * *or*/30 * * * *
Hourly
- Every hour (on the hour):
0 * * * * - Every hour at 15 minutes past the hour:
15 * * * * - Every 2 hours:
0 */2 * * *
Daily
- Every day at midnight:
0 0 * * * - Every day at 8:30 AM:
30 8 * * * - Every weekday (Monday to Friday) at 9:00 AM:
0 9 * * 1-5 - Every weekend (Saturday and Sunday) at 10:00 AM:
0 10 * * 6,0
Weekly and Monthly
- Every Monday at midnight:
0 0 * * 1 - Every 1st of the month at midnight:
0 0 1 * * - Every 15th of the month at 3:00 PM:
0 15 15 * * - At midnight on January 1st (Yearly):
0 0 1 1 *
How to use the free Cron Generator
Writing cron expressions manually is prone to errors. A misplaced asterisk or comma can mean the difference between a script running once a day and running once a minute, potentially crashing your server.
The CampaignMorph Cron Generator provides a visual interface to build and validate expressions safely.
Step 1: Select your interval
Use the interface to select how frequently you want the job to run (e.g., Minutes, Hourly, Daily, Weekly, Monthly).
Step 2: Configure the details
Depending on your selection, dropdowns will appear allowing you to specify the exact minute, hour, or day. For example, if you select "Daily," you can specify the exact time it should execute.
Step 3: Copy the expression
As you make selections, the tool generates the corresponding cron string instantly. It also provides a human-readable translation (e.g., "At 04:00 on every day-of-week from Monday through Friday") so you can verify the logic before deploying it.
Best practices for scheduling cron jobs
1. Avoid the top of the hour
If you have multiple cron jobs, avoid scheduling them all at exactly 0 * * * * (the top of the hour). This creates resource spikes on your server. Stagger them by a few minutes (e.g., 3 * * * *, 7 * * * *).
2. Understand server time zones
Cron jobs run based on the system time of the server they are hosted on. If your server is in UTC but you want a job to run at 9:00 AM EST, you must calculate the offset and write the cron expression accordingly.
3. Log your output
Cron jobs run silently in the background. If a script fails, you won't know unless you capture the output. Append >> /var/log/myjob.log 2>&1 to the end of your command in the crontab to log both standard output and errors.
4. Test before deploying
Always test your scripts manually before scheduling them via cron. Ensure they execute correctly when run from the command line, and be aware of environment variable differences (cron environments are often minimal and may not load your usual shell profile).
Further reading
If you are automating workflows, you might also find these tools useful:
- SQL Formatter - Clean up your queries before scheduling database dumps.
- JSON Formatter - Validate API responses handled by your automated scripts.
- Regex Tester - Test regular expressions used in log parsing scripts.
