Given a date, return the first day of the calendar quarter that the date falls in. The quarters are divided as follows:
- Q1: January, February, March (starts January 1)
- Q2: April, May, June (starts April 1)
- Q3: July, August, September (starts July 1)
- Q4: October, November, December (starts October 1)
Return null for null input.
Examples:
Input: inputDate = Date.newInstance(2026, 2, 15)
Output: Date.newInstance(2026, 1, 1)
Explanation: February falls in Q1 which starts on January 1
Input: inputDate = Date.newInstance(2026, 5, 20)
Output: Date.newInstance(2026, 4, 1)
Explanation: May falls in Q2 which starts on April 1
Input: inputDate = Date.newInstance(2026, 9, 1)
Output: Date.newInstance(2026, 7, 1)
Explanation: September falls in Q3 which starts on July 1
Input: inputDate = Date.newInstance(2026, 11, 30)
Output: Date.newInstance(2026, 10, 1)
Explanation: November falls in Q4 which starts on October 1
Input: inputDate = null
Output: 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 May 2026
Contest runs May 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.