Cron expression for the last day of the month

Standard cron has no way to say "last day". Months end on the 28th, 29th, 30th or 31st, so the job runs on all four and the command decides whether today is the last one.

Next runs (your time zone)

    This tool runs in your browser. We never send what you type or paste to a server.

    The expression

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

    The expression has five fields, read left to right:

    FieldValueMeaning here
    Minute0at minute 0
    Hour0at hour 0
    Day of month28-31on days 28, 29, 30 and 31
    Month*every month
    Day of week*every day of the week

    On its own, 0 0 28-31 * * runs on up to four days at the end of each month. The test after it lets the real command through only when tomorrow is the 1st.

    When it runs

    Starting from Sat 2027-02-20 00:00 UTC, the next runs are:

    Sun 2027-02-28 00:00
    Sun 2027-03-28 00:00
    Mon 2027-03-29 00:00
    Tue 2027-03-30 00:00
    Wed 2027-03-31 00:00
    Wed 2027-04-28 00:00
    Thu 2027-04-29 00:00

    These are the days the expression fires. With the test in place, the command itself runs only on 28 February and 31 March.

    Cron uses the time zone of the machine or service that runs it. The explainer at the top of this page shows the next runs in your own time zone.

    How the test works

    [ "$(date -d tomorrow +%d)" = 01 ] && echo "today is the last day of the month"

    date -d tomorrow +%d prints tomorrow's day of the month. If that is 01, today is the last day, whatever the month and including 29 February in leap years. In a crontab the % must be written \%, because cron treats a bare percent sign as the end of the command.

    -d tomorrow is GNU date, as found on Linux. On macOS and the BSDs use date -v+1d +%d.

    The caveats

    • Do not use 0 0 31 * *. It only runs in the seven months that have 31 days. Likewise 30 skips February.
    • Midnight on the last day is its start, not its end. For end-of-month reports you usually want the last minutes of the day, 59 23 28-31 * *, or simply to run at 0 0 1 * * on the first day of the next month and process the month that has just closed. The second is simpler and has no special cases.
    • The test uses the system's time zone, the same one cron uses. Keep them the same.
    • Kubernetes and GitHub Actions have only the five standard fields, so the date test has to move into the container command or a workflow step.

    Schedulers that have a "last day" symbol

    Quartz and AWS EventBridge accept L in the day-of-month field, meaning the last day of the month, so no test is needed there. Both also accept LW for the last weekday, and Quartz takes 6L in the day-of-week field for the last Friday. systemd timers do not have L either, but OnCalendar=*-*~01 00:00:00 counts days from the end of the month.

    The same schedule in other schedulers

    SchedulerExpression
    Unix cron, crontab0 0 28-31 * *
    Kubernetes CronJobschedule: "0 0 28-31 * *"
    GitHub Actions- cron: '0 0 28-31 * *'
    Quartz (Java, Spring)0 0 0 L * ?
    AWS EventBridgecron(0 0 L * ? *)

    Questions

    Is there a cron expression for the last day of the month?

    Not in standard five-field cron. Run on days 28 to 31 and let the command check that tomorrow is the 1st. Quartz and AWS EventBridge support L in the day-of-month field.

    Why does 0 0 31 * * not run every month?

    It matches only days numbered 31, so it runs in January, March, May, July, August, October and December and is skipped in the other five months.

    How do I run a job at the end of the last day of the month?

    Use 59 23 28-31 * * with the same tomorrow-is-the-1st test, or run at 00:00 on the 1st and treat it as closing the previous month.