Monthly jobs are the quiet backbone of a lot of systems: invoices generated on the first, reports rolled up on the first, logs rotated and snapshots taken on the first. The schedule sounds simple, and it is, but a lot of monthly jobs quietly turn into weekly ones because of one extra character in the wrong field. This guide builds the expression field by field, explains why the field you leave alone matters as much as the one you set, and shows how to verify the result with the free Cron Expression Builder on Ovatly.
Contents
- Quick answer
- Building the expression, field by field
- Why month length never matters for day 1
- The either-match trap, in full
- How to build and verify the schedule, step by step
- Worked example: a report at 02:30 on the first
- Limitations and honest notes
- Common mistakes
- FAQs
- Conclusion
Quick answer
Use 0 0 1 * *: minute 0, hour 0, day of month 1, every month, every day of week. It fires once a month, at midnight on the first. To fire at a different time, change only the first two fields: 30 2 1 * * is 02:30 on the first. The one thing not to do is put a value in the last field: when both day fields are restricted, standard cron fires when either one matches, and your monthly job would start running weekly as well. You can confirm all of this in the Cron Expression Builder, which explains the expression in plain English and lists the next five run times in your local time zone.
Building the expression, field by field
A cron expression is five fields in a fixed order: minute (0-59), hour (0-23), day of month (1-31), month (1-12) and day of week (0-7, where both 0 and 7 are Sunday). An asterisk means every value of that field. A monthly schedule is one decision per field:
- Minute: 0. Pin the minute so the job fires once at a chosen moment, not throughout an hour.
- Hour: 0. Pin the hour the same way. Zero gives midnight, a natural boundary for a monthly job, though any hour works.
- Day of month: 1. This is the field that does the real work: the day part of the schedule now matches only on the first day of a month.
- *Month: . An asterisk means every month. Restricting this field is how you would get a quarterly or annual job instead.
- *Day of week: . An asterisk, and it has to stay one. The next section explains why.
Assembled, that is 0 0 1 * *: four small decisions and one deliberate non-decision. The asterisk in the last field is not an unfinished answer; it is the correct, load-bearing value, and the trap section below shows why.
Why month length never matters for day 1
People sometimes worry that a monthly expression needs special handling for February, or for the months with 30 days. For a schedule pinned to the first, it does not: every month in the calendar has a first day, in leap years and ordinary years alike, so the expression fires twelve times a year with nothing to adjust.
Month length only becomes a real problem at the other end of the calendar. A day-of-month value of 31 does not exist in February, April, June, September or November, so a job pinned to the 31st silently skips those months. None of that touches day 1.
The either-match trap, in full
The rule, stated in the builder's own notes, is this: following standard cron behaviour, when both the day-of-month and day-of-week fields are restricted, a day matches if either field matches. Watch what that does to a plausible mistake. Someone writes 0 0 1 * 1 intending "the first of the month, on a Monday schedule" or copying a weekday pattern used elsewhere. Cron reads it as: fire at midnight on any day that is the first of the month, and also on any day that is a Monday. The job now runs five or six times a month, and because it still runs on the first, a quick check looks fine while the extra Monday runs go unnoticed. If a monthly job of yours runs more often than monthly, this trap is the first place to look.
How to build and verify the schedule, step by step
- Open the Cron Expression Builder and look through the schedule patterns in the list for a monthly pattern.
- Set the hour and minute you want the job to fire at, for example hour 2 and minute 30 for a quiet overnight slot.
- Read the generated expression and check it against the shape
minute hour 1 * *: day of month 1, month asterisk, day of week asterisk. - Read the plain-English description and the next five run times listed below it, shown in your local time. Every listed date should be the first of a month; if any date is not, a day field is wrong.
- Alternatively, paste
0 0 1 * *or your timed variant into the lower field and have the builder explain it back to you.
Worked example: a report at 02:30 on the first
Say a summary report should be generated at 02:30 on the first of every month, late enough that the previous month's data is complete. Only the time fields change, giving 30 2 1 * *. Pasting that into the builder produces a plain-English description of a job running at 02:30 on the first of the month, and the next-run list shows the first of next month, then the first of the month after, each at 02:30 local time. Two checks are worth doing every time: the dates all say 1, and the gaps are a month apart, including across February.
Limitations and honest notes
The builder covers standard five-field cron only. Seconds and year fields from Quartz-style schedulers are not included.
Next run times are calculated in your browser's local time. Servers usually run cron in UTC, so if your server differs, the job still fires on the first of the month, but at 00:00 or 02:30 in the server's zone, which may fall on the last day of the previous month in your local terms. Decide which time zone the "first" belongs to before choosing the hour.
Standard cron also cannot express every monthly idea. "The first Monday of the month" is beyond a single five-field expression, because the either-or rule stops the two day fields from combining into a single condition. Jobs like that need the exact day checked inside the script itself.
Common mistakes
- Adding a weekday to the last field.
0 0 1 * 1fires on the first and on every Monday. The day-of-week field must stay an asterisk for a pure monthly schedule. - Pinning the job to the 31st. Five months have no 31st, so it silently skips them.
- Leaving the minute as an asterisk.
* 0 1 * *fires every minute of the midnight hour, sixty runs instead of one. Pin the minute. - Forgetting the time zone. A first-of-the-month job at midnight UTC can land on the previous day where you live. Pick the hour in the intended zone.
- Trusting the expression without reading it back. Five fields are easy to mistype. One paste into the builder shows the next five dates.
FAQs
What is the cron expression for the first day of every month? 0 0 1 * * runs at midnight on the first of every month. Change the first two fields to move the time: 30 2 1 * * runs at 02:30 on the first instead.
Why must the day-of-week field stay an asterisk? Because of standard cron behaviour: when both day-of-month and day-of-week are restricted, a day matches if either field matches. Adding a weekday would make the job fire on the first and on that weekday every week.
Does the expression break in February or short months? No. Every month has a first day, so a day-of-month value of 1 exists in all twelve months. Short months only cause trouble for values like 31, which some months do not have.
How can I verify the schedule before saving it? Paste the expression into the Cron Expression Builder. It describes it in plain English and lists the next five run times in your local time zone, each one landing on the first of a month.
Can I run the job on the first weekday instead of the first day? Not with a single standard five-field expression. The either-or rule for the two day fields means cron cannot express 'the first day, but only if it is a weekday' on its own; that needs a check inside the script.
Conclusion
A monthly schedule in cron is one pinned field and one respected asterisk: 0 0 1 * *, with the time fields adjusted to taste and the day-of-week field left open so the either-match rule never widens it. Build it in the Cron Expression Builder, read the next five dates off the list, and the job will fire on the first of every month. If a monthly job of yours is already misbehaving, the companion guide on why a cron job is not running walks through the causes in order, and the rest of this category lives in the Developer Tools guides archive.