Cron last business day of the month

A standard cron expression cannot run a job on the last business day of the month. Cron has no concept of business days, public holidays, or a custom weekend, and a single day-of-month field cannot move when the last day falls on a Sunday or a Monday holiday. The reliable fix on your own machine is to run a daily cron job and let a short script decide whether today is the last business day.

Why a plain cron expression is not enoughLink to this section

Unix cron can express "09:00 on day 31" or "09:00 on every weekday". It cannot express "09:00 on the last weekday, unless that day is a holiday, in which case use the previous working day".

Two common attempts fail:

  • 0 9 28-31 * * fires on every day from the 28th to the 31st, not once at month end.
  • 0 9 28-31 * 1-5 does not mean "the last weekday in that range". In Vixie cron and cronie, when both the day-of-month and the day-of-week fields are restricted (not *), the fields are combined with OR. The job then runs on each of those dates, and also on every Monday to Friday.

Some schedulers go further than Unix cron. Quartz and Spring support LW, the last weekday of the month. That still skips only Saturday and Sunday. It will fire on Monday 31 May 2027, which is Memorial Day in the United States, and on Friday 31 December 2027, which is New Year's Day observed.

A daily cron plus a checkLink to this section

Run the check every day, then start the real job only when the script exits 0.

cron
HOLIDAYS_FILE=/etc/us-holidays.txt
0 9 * * * /usr/local/bin/last-business-day.sh && /usr/local/bin/month-end-job

The shell script below uses GNU date (Linux). Pass a date as YYYY-MM-DD to test a day other than today. Without HOLIDAYS_FILE, Saturday and Sunday are the only non-working days. With a file of YYYY-MM-DD holidays, one date per line, the script walks backward from the last calendar day until it finds a weekday that is not in the list.

bash
#!/usr/bin/env bash
# Exit 0 only if the given date (default: today) is the last business day of its month.
# Weekends are Saturday and Sunday. Optional HOLIDAYS_FILE has one YYYY-MM-DD per line.
set -euo pipefail

day="${1:-$(date +%F)}"

is_weekend() {
  local dow
  dow=$(date -d "$1" +%u) # 1=Monday ... 7=Sunday
  [[ "$dow" -ge 6 ]]
}

is_off() {
  if is_weekend "$1"; then
    return 0
  fi
  if [[ -n "${HOLIDAYS_FILE:-}" && -f "${HOLIDAYS_FILE}" ]]; then
    if grep -qx "$1" "$HOLIDAYS_FILE"; then
      return 0
    fi
  fi
  return 1
}

year=$(date -d "$day" +%Y)
month=$(date -d "$day" +%m)
candidate=$(date -d "$year-$month-01 +1 month -1 day" +%F)
while is_off "$candidate"; do
  candidate=$(date -d "$candidate -1 day" +%F)
done

if [[ "$candidate" == "$day" ]]; then
  exit 0
fi
exit 1

This script was tested on every date in 2026 and 2027 against the United States federal holiday calendar from python-holidays 0.109. A Node.js port of the same rules was tested on the same 730 days and agreed in every case. You still have to keep the holiday file up to date, and the cron entry still starts once every day.

Last weekday and last US business day, 2026-2027Link to this section

The table uses a Saturday-Sunday weekend and the United States federal calendar, including observed dates. That is the calendar produced by python-holidays for country code US, which is the library AnyMoment's business calendar uses. "Last weekday" ignores holidays. "Last US business day" skips them. Rows that differ are marked with an asterisk.

MonthLast calendar dayLast weekdayLast US business day
Jan 2026Sat 2026-01-31Fri 2026-01-30Fri 2026-01-30
Feb 2026Sat 2026-02-28Fri 2026-02-27Fri 2026-02-27
Mar 2026Tue 2026-03-31Tue 2026-03-31Tue 2026-03-31
Apr 2026Thu 2026-04-30Thu 2026-04-30Thu 2026-04-30
May 2026Sun 2026-05-31Fri 2026-05-29Fri 2026-05-29
Jun 2026Tue 2026-06-30Tue 2026-06-30Tue 2026-06-30
Jul 2026Fri 2026-07-31Fri 2026-07-31Fri 2026-07-31
Aug 2026Mon 2026-08-31Mon 2026-08-31Mon 2026-08-31
Sep 2026Wed 2026-09-30Wed 2026-09-30Wed 2026-09-30
Oct 2026Sat 2026-10-31Fri 2026-10-30Fri 2026-10-30
Nov 2026Mon 2026-11-30Mon 2026-11-30Mon 2026-11-30
Dec 2026Thu 2026-12-31Thu 2026-12-31Thu 2026-12-31
Jan 2027Sun 2027-01-31Fri 2027-01-29Fri 2027-01-29
Feb 2027Sun 2027-02-28Fri 2027-02-26Fri 2027-02-26
Mar 2027Wed 2027-03-31Wed 2027-03-31Wed 2027-03-31
Apr 2027Fri 2027-04-30Fri 2027-04-30Fri 2027-04-30
May 2027Mon 2027-05-31Mon 2027-05-31Fri 2027-05-28 *
Jun 2027Wed 2027-06-30Wed 2027-06-30Wed 2027-06-30
Jul 2027Sat 2027-07-31Fri 2027-07-30Fri 2027-07-30
Aug 2027Tue 2027-08-31Tue 2027-08-31Tue 2027-08-31
Sep 2027Thu 2027-09-30Thu 2027-09-30Thu 2027-09-30
Oct 2027Sun 2027-10-31Fri 2027-10-29Fri 2027-10-29
Nov 2027Tue 2027-11-30Tue 2027-11-30Tue 2027-11-30
Dec 2027Fri 2027-12-31Fri 2027-12-31Thu 2027-12-30 *

In May 2027 the last weekday is Monday 31 May, Memorial Day, so the last US business day is Friday 28 May. In December 2027 the last weekday is Friday 31 December, New Year's Day observed (1 January 2028 is a Saturday), so the last US business day is Thursday 30 December. In January 2026 the last calendar day is Saturday 31, so even a weekday-only rule must move to Friday 30. That is why "day 31" is not a substitute for a last-business-day check.

If your weekend is not Saturday and Sunday, or you close on extra days, change the weekend test and the holiday file. The dates above will no longer apply.

An option that fires only on that dayLink to this section

If you would rather not run a daily filter or maintain a holiday file, AnyMoment can store the rule and POST to your URL only on the last business day.

In the app, describe the rule in plain language, for example: "last business day of every month at 09:00, using the US holiday calendar". Preview the dates before you rely on them. The HTTP API can set the same rule with type set to last_business_day and a business_calendar: a country code such as US or GB, an optional subdivision, custom weekend_days, extra closures, and extra_workdays. You can also roll a fixed day of the month forward, backward, to the nearest business day, or skip it.

Then create an outgoing webhook subscription on the calendar. AnyMoment POSTs to your HTTPS URL when an occurrence is due (occurrence.due). You can shift that delivery with occurrence_offset_seconds. A signing secret is returned once. Deliveries are logged and can be replayed. The URL can be an n8n Webhook node, a Zapier Catch Hook, Make, or your own server. Outgoing webhooks require a Pro plan or an active trial. New accounts get a 30-day trial with the full product.

Start at anymoment.sineways.tech. The API reference is at api.anymoment.sineways.tech/docs.