Cron expression for the last day of the month
At 00:00, on the last day of the month.
Next 10 runs
In Quartz, worked out in your browser from the current time.
At a glance
- Runs
- 12 in 2027
- Gap between runs
- 28 days to 31 days
- Expressible in
- EventBridge and Quartz; workarounds for the rest
- Clock changes
- No effect in the zones checked
In each dialect
Every expression here is generated by the tester’s own engine and checked run for run against the others, so “Exact” means the same clock times in the same zone. Each one links to the tester.
Standard cron has no L. The last or nearest weekday changes from month to month, and plain cron fields cannot follow it.
Workaround
Schedule 0 0 28-31 * * (at 00:00, on the 28th through the 31st of the month) and let a shell test go ahead only when tomorrow is the 1st. In a crontab, % must be written \%, or cron cuts the line there.
0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /path/to/commandaws events put-rule --name last-day-of-month --schedule-expression "cron(0 0 L * ? *)"- Wrap it in
cron(…). Day of month is set (L), so day of week has to be?. The final*is the required year field. - Scheduled rules always run in UTC. For local times, create it in EventBridge Scheduler with
--schedule-expression-timezone.
CronScheduleBuilder.cronSchedule("0 0 0 L * ?")- The leading
0is the seconds field, so it fires at the top of the minute. Day of month is set (L), so day of week has to be?. The optional year is left off. - Uses the JVM’s default zone unless the trigger sets one with
inTimeZone.
Kubernetes CronJob has no L. The last or nearest weekday changes from month to month, and plain cron fields cannot follow it.
Workaround
Schedule 0 0 28-31 * * and put the test in front of the container’s command, so the Job exits straight away unless tomorrow is the 1st. The test uses GNU date, so Alpine and other BusyBox images need coreutils. The container’s clock is UTC unless you set TZ; match it to timeZone.
schedule: "0 0 28-31 * *"
# in the container:
command: ["sh", "-c", "[ \"$(date -d tomorrow +%d)\" = 01 ] && exec /app/job"]GitHub Actions has no L. The last or nearest weekday changes from month to month, and plain cron fields cannot follow it.
Workaround
Schedule 0 0 28-31 * * and make the test the first line of the step that does the work, so the step ends early unless tomorrow is the 1st. The runner’s clock is UTC; if you set timezone, give the step the same zone with env: TZ.
- cron: '0 0 28-31 * *'
# in the job:
- run: |
[ "$(date -d tomorrow +%d)" = 01 ] || exit 0
./your-scriptAzure Functions has no L. The last or nearest weekday changes from month to month, and plain cron fields cannot follow it.
Workaround
Schedule 0 0 0 28-31 * * and return early unless tomorrow is the 1st. UtcNow matches the default UTC schedule; if you set WEBSITE_TIME_ZONE, compare local time instead.
[TimerTrigger("0 0 0 28-31 * *")]
// first line of the function:
if (DateTime.UtcNow.AddDays(1).Day != 1) return;About this schedule
The last day moves between the 28th and the 31st, so a plain day-of-month value cannot follow it. Quartz and EventBridge have L for exactly this. The others run on the 28th to the 31st and let a date check go ahead only when tomorrow is the 1st.
Clock changes
None of these times falls in the hour that clocks skip or repeat in New York, London, Berlin, Helsinki or Sydney, so every dialect runs it normally all year there. Zones that change clocks at other hours can still differ.
Questions
- What is the cron expression for the last day of the month?
- It is
0 0 L * ? *in EventBridge and0 0 0 L * ?in Quartz. Standard cron, Kubernetes, GitHub Actions and Azure cannot express it in one line, so this page gives a tested workaround for each. - Can a Kubernetes CronJob run on the last day of the month?
- Not with the schedule alone. Schedule
0 0 28-31 * *and put the test in front of the container’s command, so the Job exits straight away unless tomorrow is the 1st. The test uses GNUdate, so Alpine and other BusyBox images needcoreutils. The container’s clock is UTC unless you setTZ; match it totimeZone.