Given a date, return the last day of its calendar quarter. Calendar quarters are: Q1 (January-March), Q2 (April-June), Q3 (July-September), Q4 (October-December). Return null for null input.
Examples:
Input: d = Date.newInstance(2026, 2, 15)
Output: Date.newInstance(2026, 3, 31)
Explanation: February is in Q1, which ends on March 31
Input: d = Date.newInstance(2026, 5, 1)
Output: Date.newInstance(2026, 6, 30)
Explanation: May is in Q2, which ends on June 30
Input: d = Date.newInstance(2026, 9, 30)
Output: Date.newInstance(2026, 9, 30)
Explanation: September 30 is already the last day of Q3
Input: d = Date.newInstance(2026, 12, 25)
Output: Date.newInstance(2026, 12, 31)
Explanation: December is in Q4, which ends on December 31
Input: d = null
Output: null
Explanation: Null input returns null
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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 Mar 2026
Contest runs March 3 - 31. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.