T
ToolPrime

Cron Expression for the Last Day of Every Month

Approximate the last day of each month using 0 0 28-31 * *. Standard cron cannot directly express "last day," so scripts or special syntax may be needed.

Expression

0 0 28-31 * *

At 00:00 on days 28-31 of every month (approximate)

Use Cases

Code Examples

Crontab

# At 00:00 on days 28-31 of every month (approximate)
0 0 28-31 * * /path/to/your/script.sh

GitHub Actions

name: Scheduled Job
on:
  schedule:
    - cron: '0 0 28-31 * *'
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "Running Last Day of Every Month"

systemd Timer

[Unit]
Description=Last Day of Every Month timer

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true

[Install]
WantedBy=timers.target

node-cron (Node.js)

import cron from 'node-cron'

// At 00:00 on days 28-31 of every month (approximate)
cron.schedule('0 0 28-31 * *', () => {
  console.log('Running Last Day of Every Month')
})

Spring (@Scheduled, Java)

// At 00:00 on days 28-31 of every month (approximate)
@Scheduled(cron = "0 0 0 28-31 * *")
public void run() {
    // your task
}

Spring cron has 6 fields (a leading seconds field), so a 0 is prepended to the standard 5-field expression.

Tips

Frequently Asked Questions

Can cron run on the last day of the month?

Standard five-field cron cannot express "last day" directly. The common workaround is to run a wrapper script daily that checks if tomorrow is the 1st. Some extended cron implementations (like AWS, Quartz) support the L character for last day.

What happens if I specify day 31 in February?

Cron simply skips the execution when the day does not exist. A cron job set for day 31 will not run in February, April, June, September, or November.

Related Cron Expressions

Related Tools