Given a date, return the fiscal quarter number (1-4) based on calendar quarters. Q1 is January-March, Q2 is April-June, Q3 is July-September, Q4 is October-December. Return null if the input date is null.

Examples:

Input: inputDate = Date.newInstance(2025, 2, 15) Output: 1 Explanation: February is in Q1 (January-March) Input: inputDate = Date.newInstance(2025, 7, 1) Output: 3 Explanation: July is in Q3 (July-September) Input: inputDate = Date.newInstance(2025, 12, 31) Output: 4 Explanation: December is in Q4 (October-December) Input: inputDate = 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 account

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

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.