Given a Date, return the number of days remaining until the last day of that same month. The given date itself is not counted, so for March 1 the answer is 30 because the last day is March 31. For the last day of the month the answer is 0. Return null when the input is null. The implementation must correctly handle leap years for February.
Examples:
Input: inputDate = 2026-03-01
Output: 30
Explanation: March has 31 days, so 31 minus 1 equals 30 days remaining.
Input: inputDate = 2026-03-15
Output: 16
Explanation: 31 minus 15 equals 16 days remaining in March.
Input: inputDate = 2026-03-31
Output: 0
Explanation: The given date is already the last day.
Input: inputDate = 2024-02-28
Output: 1
Explanation: 2024 is a leap year so February has 29 days.
Input: inputDate = null
Output: null
Explanation: Null input returns null.
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 July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.