Cron every Sunday at midnight: 0 0 * * 0 and @weekly
0 0 * * 0 runs once a week at midnight on Sunday. It is precisely what the @weekly macro expands to, and 0 0 * * 7 is the same schedule.
At a glance
- Expression
- 0 0 * * 0
- Fires
- Once a week, 52 or 53 times a year.
- Restricted fields
- Minute, hour and day of week pinned. Day of month and month open.
- Equivalent macro
- @weekly, which expands to exactly 0 0 * * 0.
- Sunday values
- Both 0 and 7 mean Sunday. The parser folds 7 to 0.
- Start of the week
- The day of week field starts at Sunday, which is why @weekly lands there rather than on Monday.
In detail
Sunday is the day the day of week field starts on, so it carries the value 0, and it is also accepted as 7 at the top of the range. The parser folds 7 to 0 before matching, which means 0 0 * * 7 and 0 0 * * 0 are the same expression and 0 0 * * 0,7 is not two days.
This particular combination has a macro. @weekly expands to 0 0 * * 0, so a crontab line beginning @weekly is midnight on Sunday and nothing else. That is worth knowing because plenty of people write @weekly meaning some time each week and are then surprised that it collides with @monthly and @daily at the start of every month.
Sunday midnight is the boundary between weeks for anything using the day of week field, and it is a natural place for a weekly rollup. It is also the moment when @weekly, @daily and, on the first of a month, @monthly and possibly @yearly all fire together, which is a real pile up on a machine with a lot of macro scheduled jobs.
For a weekly job the definition of the week matters more than the schedule does. If the report covers the previous seven days, a run at Sunday 00:00 covers Sunday through Saturday, which is not the same week that a business using Monday to Sunday would recognise. Decide the boundary first, then pick the day.
Examples
0 0 * * 0@weekly /opt/app/bin/rollup.sh >> /var/log/rollup.log 2>&1Identical schedule, expanded by the parser to 0 0 * * 0.
40 2 * * SUN /opt/app/bin/rollup.sh02:40 on Sunday, clear of everything that starts at midnight.
Things that catch people out
- @weekly is not any day of the week. It is Sunday at midnight, exactly.
- 0 0 * * 0,7 looks like two days and matches one, because 7 folds to 0.
- A weekly rollup that runs at Sunday 00:00 and looks back seven days covers the week ending Saturday night, which may not be the week your business reports on.
Try it: Cron Expression Parser
Paste any five or six field expression to get a plain English description, a per field breakdown and the next run times in your local time.
Cron Expression Parser
LOCAL · Browser-OnlyParse cron expressions and see the next scheduled run times
Supports 5-field (minute hour day month weekday), 6-field (with seconds), named values (JAN, MON), and @macros (@daily, @hourly, ...)
Use the dropdowns below to build your cron expression visually, or type a custom value in each field.
Human-Readable Description
Every 5 minutes
Field Breakdown
| Field | Allowed | Value | Meaning |
|---|---|---|---|
| Minute | 0-59 | */5 | every 5 minute(s) |
| Hour | 0-23 | * | every hour |
| Day of Month | 1-31 | * | every day of month |
| Month | 1-12 | * | every month |
| Day of Week | 0-7 | * | every day of week |
Related cron expressions
All cron expressions →Cron every Monday at 9 AM: 0 9 * * 1
0 9 * * 1 runs at 09:00 every Monday, 52 or 53 times a year. Day 1 is Monday, and the fifth field is the only one that needs to change.
Cron macros: @daily, @weekly, @monthly and the rest
Seven macros expand to ordinary five field expressions, and @reboot has no scheduled time at all. Here is exactly what each one becomes.
The cron day of week field: 0 to 7 with Sunday at both ends
The day of week field runs 0 to 7 with Sunday as both 0 and 7, and accepts SUN through SAT. Restricting it changes how the day of month field behaves.
Cron at the weekend: 0 0 * * 0,6
0 0 * * 0,6 runs at midnight on Saturday and Sunday, twice a week. Why 6-7 works too, and why 6-0 is rejected as an invalid range.
Cron every Friday at 5 PM: 0 17 * * 5
0 17 * * 5 runs at 17:00 every Friday, once a week. Cron uses a 24 hour clock, so five in the afternoon is 17 and there is no PM suffix.
Cron on Monday, Wednesday and Friday: 0 0 * * 1,3,5
0 0 * * 1,3,5 runs on Monday, Wednesday and Friday, three times a week. A comma list is required because a step cannot skip weekend days.
Tools for this
- Cron Expression Parser Free online cron expression parser - parse cron expressions and see the next scheduled run times
- Crontab Generator Free online crontab generator - build cron expressions visually with an intuitive interface