Last day of month with Cron Studio
This opens the Quartz expression 0 0 12 L * ?, which fires at noon on the last day of every month, whether it has 28, 30 or 31 days. Plain crontab has no L, and the page shows the workaround.
- Read the plain-English line and the next month-end dates; February and 30-day months are handled.
- If you use Quartz, Spring or AWS EventBridge, copy the expression as it is.
- On a plain crontab, use 0 12 28-31 * * with a test that tomorrow is day 1 (shown below).
- Remember to escape every % in a crontab line.
What to know
Quartz, Spring and AWS EventBridge understand L in the day-of-month field: 0 0 12 L * ? runs at 12:00 on the last day of each month. L-3 means three days before the end, and LW means the last weekday. Unix crontab has none of this.
On unix, schedule the job for days 28 to 31 and let the command decide: 0 12 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /path/to/job. The test only succeeds on the real last day. The backslash before % is required because cron treats an unescaped % as a newline. date -d tomorrow is GNU date; on macOS or BSD use date -v+1d +\%d.
Do not write 0 0 31 * *: it only runs in months that have 31 days, and 0 0 30 2 * never runs at all. If a month-end report seems to be missing in some months, this is almost always why: the schedule names a day that those months do not have, and cron never complains about it.
Updated · Cosmovex
Questions
What is the cron expression for the last day of the month?
In Quartz, Spring and AWS EventBridge: 0 0 12 L * ?. In plain unix cron there is no such expression; run on days 28-31 and test whether tomorrow is the 1st.
Why does 0 0 31 * * skip some months?
Because day 31 only exists in seven months. Cron does not clamp to the last day; in months without a 31st the job simply does not run.
Does the L workaround handle February and leap years?
Yes. The test runs on days 28 to 31 and succeeds only when tomorrow is day 1, so it fires on the 28th in a common February, the 29th in a leap year and the 30th or 31st otherwise.
Why does my crontab line with date +%d fail?
Cron treats an unescaped % as a newline. Write date +\%d. The Audit tab in Cron Studio flags this mistake.
The free plan covers everything on this page. Cron Studio Pro ($19, paid once) is described on the Cron Studio page.