How to Write a Cron Expression (Beginner Guide)

Developer

Learn the 5-field cron syntax with examples, common patterns, and tips to schedule any recurring task correctly.

Step-by-Step Guide

1

Understand the 5 Fields

A cron expression has 5 space-separated fields: minute (0–59), hour (0–23), day-of-month (1–31), month (1–12), day-of-week (0–7, where 0 and 7 are Sunday). Example: `30 9 * * 1` means "every Monday at 9:30 AM".

2

Use the Asterisk (*) for "Every"

An asterisk means "every valid value". `* * * * *` runs every minute. `0 * * * *` runs at the start of every hour. `0 0 * * *` runs at midnight every day.

3

Use Commas for Multiple Values

Commas list specific values. `0 9 * * 1,3,5` runs at 9:00 on Monday, Wednesday, and Friday. `0 0 1,15 * *` runs at midnight on the 1st and 15th of every month.

4

Use Slashes for Intervals

Slashes define step intervals. `*/15 * * * *` runs every 15 minutes. `0 */6 * * *` runs every 6 hours. `*/5 9-17 * * *` runs every 5 minutes between 9 AM and 5 PM.

5

Use Hyphens for Ranges

Hyphens specify a range. `0 9-17 * * 1-5` runs every hour from 9 AM to 5 PM on weekdays. Combine with commas and slashes for complex schedules.

Try Our Free Tool

Cron Generator

Frequently Asked Questions

Q: How do I run a job every 30 minutes?

A: `*/30 * * * *` or `0,30 * * * *` — both expressions run the job at the top and half of every hour.

Q: What timezone does cron use?

A: Traditional cron uses the system timezone of the server. Cloud schedulers (AWS EventBridge, GitHub Actions) often default to UTC. Always check the timezone setting for your specific platform.

Q: What is the difference between day-of-month and day-of-week?

A: If both fields are set to non-asterisk values, most cron implementations run the job when EITHER condition is met (logical OR). Use `*` for the one you do not want to restrict.

Related Guides