Build Expression
What is a Cron Expression?
A cron expression is a string of 5 fields separated by spaces that defines when a scheduled task should run. Each field represents a time unit: minute, hour, day of month, month, and day of week. This format is used by Unix-like systems, CI/CD pipelines, cloud functions, and task schedulers worldwide.
Cron Expression Syntax
Cron expressions consist of five fields in the order: Minute Hour Day-of-Month Month Day-of-Week. Each field accepts specific values: Minutes use numbers 0-59, hours use 0-23, days of month use 1-31, months use 1-12 or names (JAN-DEC), and weekdays use 0-6 or names (SUN-SAT). Special characters include asterisks (*) for any value, commas (,) for lists, hyphens (-) for ranges, and forward slashes (/) for steps. For example, */15 means every 15 units, 1-5 means through 5, and 0,30 means at 0 and 30.
Common Cron Patterns
| Expression | Description |
|---|---|
| 0 * * * * | Every hour on the hour |
| 0 9 * * 1-5 | 9 AM on weekdays |
| */15 * * * * | Every 15 minutes |
| 0 0 1 * * | Midnight on the 1st |
| 30 2 * * 0 | 2:30 AM every Sunday |
| 0 0 * * * | Daily at midnight |
Frequently Asked Questions
What timezone do cron jobs use?
Most systems use UTC timezone for cron jobs. Adjust your expression accordingly for local execution times. For example, a job scheduled at 9 AM PST should be set to 17:00 UTC.
Can I use both day-of-month and day-of-week?
Yes, when both fields are specified, the job runs when either field matches. For example, 0 9 15 * * runs at 9 AM on the 15th of every month AND on every Monday.
What do the day-of-week numbers mean?
In cron syntax, 0 and 7 both represent Sunday, 1 is Monday, 2 is Tuesday, up to 6 for Saturday. Some systems prefer 0=Sunday while others use 0-6 with Sunday at 0.
How do I run a job every Monday?
Set the day-of-week field to 1 (Monday). Use 0 9 * * 1 to run at 9 AM every Monday. The * in other fields means every day and every month.
What is the difference between * and ?
In standard cron, * means "any value." Some variants like Quartz use ? for "any" when you have already specified either day-of-month OR day-of-week but not both.
How do I specify every quarter?
To run on the first day of every quarter (January, April, July, October) at midnight, use 0 0 1 1,4,7,10 *. The comma separates multiple values in a list.
Use Cases
- Automation: Schedule scripts to run backups, cleanup tasks, or reports at specific times
- CI/CD Pipelines: Trigger builds and deployments on schedule (midnight deployment, weekly release)
- Cloud Functions: Schedule AWS Lambda, Google Cloud Functions, or Azure Functions
- Monitoring: Run health checks, log rotation, or system maintenance tasks