Cron Expression for Last Day of Month

No direct cron syntax. Use: 0 0 28-31 * * with a day check.

Why Cron Cannot Do This Directly

Standard cron has no "last day of month" keyword. Months have 28, 29, 30, or 31 days, so no single day-of-month value works for all months.

The Workaround

Schedule the job to run on days 28 through 31, but add a shell condition that checks if tomorrow is the 1st (meaning today is the last day):

0 0 28-31 * * [ "$(date +\%d -d tomorrow)" = "01" ] && /your/command

Extended Cron (Quartz, Spring)

Some cron implementations support an L modifier. In Quartz Scheduler, you can write 0 0 0 L * ? to mean "midnight on the last day of every month."

Try the Cron Expression Builder to create and test cron schedules.

Related Questions