Given a date, return the last business day of the month that date falls in. A business day is any day from Monday through Friday, so a month that ends on a Saturday or Sunday steps back to the Friday before it.
If the input date is null, return null.
Examples:
Input: input = 2024-04-15
Output: 2024-04-30
Explanation: April 2024 ends on Tuesday the 30th, which is already a business day
Input: input = 2024-03-10
Output: 2024-03-29
Explanation: March 2024 ends on Sunday the 31st, so the answer steps back to Friday the 29th
Input: input = 2024-06-01
Output: 2024-06-28
Explanation: June 2024 ends on Sunday the 30th, so the answer is Friday the 28th
Input: input = 2024-02-05
Output: 2024-02-29
Explanation: 2024 is a leap year and February 29th is a Thursday
Input: input = null
Output: null
Explanation: A null date produces a null result
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay November 2026 (Nov 16–30)Sponsored by FLXBL
Contest runs November 16 - 30. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.