The Ultimate Guide to Cron Expressions
A cron expression is a string comprising five or six fields separated by white space that represents a set of times, normally as a schedule to execute a routine or script. Originally developed for the Unix operating system (the `cron` daemon), it has become the standard scheduling syntax used by modern CI/CD pipelines (like GitHub Actions, GitLab CI), cloud providers (AWS CloudWatch, Google Cloud Scheduler), and backend programming frameworks (Node.js, Python, PHP).
Anatomy of a Cron String
A standard cron string consists of 5 parts (some systems support a 6th for seconds, but 5 is the industry standard). Our free cron generator focuses on the standard 5 parts:
- * * * * *
- | | | | |
- | | | | +----- Day of week (0 - 6) (Sunday=0)
- | | | +------- Month (1 - 12)
- | | +--------- Day of month (1 - 31)
- | +----------- Hour (0 - 23)
- +------------- Minute (0 - 59)
Special Characters in Cron
Understanding special characters is the key to mastering cron:
- Asterisk (*) - Matches all values. For example, an asterisk in the minute field means "every minute".
- Hyphen (-) - Defines a range. `1-5` in the day of week field means "Monday through Friday".
- Comma (,) - Separates discrete items in a list. `0,15,30,45` means "at the top of the hour, at quarter past, at half past, and at quarter to".
- Slash (/) - Specifies increments. `*/5` in the minute field means "every 5 minutes".
Human-Readable Cron Validation
One of the hardest parts of writing cron jobs is knowing whether your string actually does what you think it does. That's why our tool integrates a real-time natural language translator. As you type your cron schedule, the tool will instantly translate it into plain English (e.g., "At 12:00 PM, on day 15 of the month"). This guarantees you never accidentally schedule a script to run every minute instead of once a month!
Frequently Asked Questions (FAQ)
Are cron jobs timezone dependent?
Yes. By default, a cron job executes based on the local timezone of the server it is running on. However, many cloud providers (like AWS or GitHub Actions) run their servers in UTC by default. Always verify your server's timezone.
How do I schedule a job to run every 30 seconds?
Standard 5-part cron does not support seconds. To bypass this, developers often write a script that runs every minute (`* * * * *`), executes the task, pauses for 30 seconds (`sleep 30`), and then executes the task again.
Does 0 or 7 mean Sunday?
In the vast majority of cron implementations, both 0 and 7 represent Sunday. Monday is 1, Tuesday is 2, etc.