Skip to content
Cron Expression Guide: Syntax, Examples & Common Schedules

Cron Expression Guide: Syntax, Examples & Common Schedules

What Is a Cron Expression?

A cron expression is a string that defines a schedule for automated tasks. Originally from Unix, cron expressions are now used everywhere: Linux crontabs, CI/CD pipelines, cloud schedulers (AWS CloudWatch, Google Cloud Scheduler), Kubernetes CronJobs, database maintenance scripts, and application task runners.

Understanding cron expression syntax saves you from guesswork and misconfigured schedules. This guide covers the format, walks through practical examples, and provides ready-to-use expressions for common schedules.

Cron Expression Syntax

A standard cron expression has five fields separated by spaces:

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, where 0 = Sunday)
│ │ │ │ │
* * * * *

Each field accepts specific values, ranges, wildcards, and special characters.

Field Values

FieldAllowed ValuesSpecial Characters
Minute0-59* , - /
Hour0-23* , - /
Day of month1-31* , - / ? L W
Month1-12 or JAN-DEC* , - /
Day of week0-6 or SUN-SAT* , - / ? L #

Special Characters

  • * (asterisk): Matches every value. * * * * * means every minute of every hour of every day.
  • , (comma): Lists multiple values. 1,15 means the 1st and 15th.
  • - (hyphen): Defines a range. 1-5 means 1 through 5.
  • / (slash): Defines a step. */5 means every 5 units. 0/15 means starting at 0, every 15 units.
  • ? (question mark): Used in day-of-month or day-of-week to mean “no specific value.” Not supported in all implementations.
  • L: Last. In day-of-month, L means the last day of the month. In day-of-week, 5L means the last Friday.
  • W: Nearest weekday. 15W means the nearest weekday to the 15th of the month.
  • #: Nth occurrence. 5#2 means the second Friday of the month.

Note: L, W, and # are extensions supported by Quartz, Spring, and some cloud schedulers but not by standard Unix cron.

Common Cron Schedules

Here are the cron expressions you will use most often:

Every Minute

* * * * *

Useful for health checks or real-time monitoring. Not recommended for heavy tasks.

Every 5 Minutes

*/5 * * * *

A common interval for polling, cache refreshing, or lightweight data syncs. See the every 5 minutes cron reference for implementation details.

Every 15 Minutes

*/15 * * * *

Good for metrics collection, queue processing, or moderate-frequency jobs.

Every Hour (On the Hour)

0 * * * *

Runs at minute 0 of every hour. Use for hourly reports, cleanups, or aggregations.

Every Day at Midnight

0 0 * * *

The classic daily job. Runs at 00:00 every day. Used for daily backups, report generation, and log rotation. See the daily midnight cron reference for more examples.

Every Day at 9:00 AM

0 9 * * *

Common for sending daily digest emails or notifications during business hours.

Every Monday at 8:00 AM

0 8 * * 1

Weekly tasks: reports, newsletter sends, or database maintenance.

First Day of Every Month at Midnight

0 0 1 * *

Monthly tasks: billing, invoicing, monthly reports.

Every Weekday at 6:00 PM

0 18 * * 1-5

Monday through Friday. End-of-day reporting or cleanup tasks.

Every 30 Minutes During Business Hours

*/30 9-17 * * 1-5

Runs every 30 minutes between 9 AM and 5 PM, Monday through Friday.

Advanced Cron Examples

Twice a Day (9 AM and 5 PM)

0 9,17 * * *

Uses a comma to specify two exact hours.

Every Quarter Hour During Specific Hours

0,15,30,45 8-18 * * *

Runs at minutes 0, 15, 30, and 45 during hours 8 through 18.

Last Day of Every Month

0 0 L * *

Uses the L special character. Note: this requires a cron implementation that supports L (Quartz, Spring, AWS).

For standard Unix cron, you can approximate this with:

0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && your_command

Every Other Wednesday

This is not directly expressible in standard cron. You would schedule every Wednesday and add application logic to check if it is the right week:

0 9 * * 3

Then in your script, check the week number.

Time Zones

Cron expressions do not include time zone information. The schedule runs in whatever time zone the cron daemon or scheduler is configured to use.

  • Linux crontab: Uses the system time zone by default. Set TZ in the crontab to override.
  • Kubernetes CronJobs: Uses the kube-controller-manager time zone (usually UTC). As of Kubernetes 1.27+, you can set .spec.timeZone.
  • AWS CloudWatch Events: Always UTC.
  • GitHub Actions: Always UTC.

Always verify which time zone your scheduler uses. A job scheduled for 0 9 * * * runs at 9 AM UTC on AWS, which is 4 AM Eastern or 1 AM Pacific.

Six-Field and Seven-Field Expressions

Some systems extend the standard five-field format:

Six Fields (With Seconds)

seconds minute hour day month weekday
0 */5 * * * *

Used by Quartz (Java), Spring Framework, and some task schedulers. The leading field is seconds (0-59).

Seven Fields (With Year)

seconds minute hour day month weekday year
0 0 12 * * ? 2026

Used by Quartz. The optional seventh field specifies the year.

If you are working with a six-field or seven-field system, check your scheduler’s documentation to confirm the field order.

Common Mistakes

Forgetting Time Zones

Your job runs at 3 AM — but 3 AM in which time zone? Always confirm.

Overlapping Executions

If a job takes 10 minutes to run but is scheduled every 5 minutes, you will have overlapping executions. Use a lock mechanism or ensure your job runner prevents concurrent instances.

Day of Month + Day of Week Conflicts

In standard cron, if you set both day-of-month and day-of-week, the job runs when either condition is true (OR logic). This is counterintuitive. Most people expect AND logic.

0 9 15 * 1

This runs on the 15th of every month AND every Monday, not on the 15th only if it is a Monday.

Wildcard Overuse

* * * * * runs every minute. That is 1,440 executions per day. Make sure your infrastructure can handle the frequency you configure.

Testing Your Cron Expressions

Before deploying a cron schedule to production, always test it. Verify that it produces the dates and times you expect. Online cron expression tools let you input an expression and see the next several execution times, which is the fastest way to catch errors.

For other common development tasks like formatting data or encoding strings, the devcraft toolkit has free browser-based tools that fit naturally into your workflow.

Conclusion

Cron expressions are a compact, powerful way to define schedules. The five-field syntax covers most use cases, and special characters like /, ,, and - give you flexibility for complex schedules. Always test your expressions before deploying, and always verify the time zone.

Bookmark this guide for quick reference, and check out the devcraft developer tools for more productivity boosters that make your daily work faster.