Cron expression for the first day of the month
Runs the job at midnight on the 1st of every month.
0 0 1 * *
At 12:00 AM, on day 1 of the month
Field by field
- Minute · 0–59
0only at minute 0 - Hour · 0–23
0only at 00:00 - Day of month · 1–31
1only on day 1 - Month · 1–12 or JAN–DEC
*every month - Day of week · 0–7 or SUN–SAT
*every day of the week
Next runs in your local time
Why this schedule, and when it bites
The first of the month is the natural boundary for everything that resets: invoices, quotas, storage reports. 0 0 1 * * is one restricted field, day-of-month 1, and it is the cleanest monthly schedule cron can express. The trap is adding a weekday next to it: when both day-of-month and day-of-week are restricted, cron fires on the union, not the intersection.
Day and weekday restricted together widen, they do not narrow. 0 0 1 * 1 does not mean the first Monday of the month. It means the 1st of the month OR every Monday. One of the two fields must stay a star if the run has to match both conditions.
Midnight computes yesterday's data. At 00:00 on the 1st, the month that just ended is complete, which is usually what the report wants. A job that sums the last 24 hours at that moment sums the previous day of the new month. State the window explicitly in the script.
Retries after a failed night. If the run fails at 00:05 and is retried at 09:00, everything downstream assumes the 00:00 data exists. Make the job write a marker and make the retry idempotent, so a manual re-run cannot double-post an invoice.
Where this cron expression shows up
- Monthly invoicing
- Resetting counters that roll over with the calendar
- Storage and cost reports for the month just gone
Common variations
-
The last day of the month
0 0 L * * At 12:00 AM, on the last day of the month
-
On the 1st and the 15th
0 0 1,15 * * At 12:00 AM, on days 1 and 15 of the month
Ranges, steps, and names are spelled out on the cheat sheet.
Questions this schedule raises
Why does my first-of-month job also run on some Mondays?
Because the weekday field carries a restriction too. In cron, restricting both day-of-month and day-of-week fires on the union of the two sets. Keep one of them as a star to get intersection behaviour.
How do I run at 9 AM on the first?
0 9 1 * *. The hour moves to 9, the day stays 1, and the job fires at 09:00 on the first of each month in the daemon's timezone.