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!

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 September 2026 (Sep 16–30)Sponsored by FLXBL

Contest runs September 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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In