Given a Date, return the week number of the year (1-53). The week number is calculated based on the day of the year, where week 1 starts on January 1st.

Calculate the week number using a simple formula: divide the day of the year by 7 and round up. For example, day 1-7 is week 1, day 8-14 is week 2, and so on.

Method signature: public static Integer getWeekNumber(Date inputDate)

Examples:

Input: inputDate = 2026-01-05 Output: 1 Explanation: Day 5 of the year is in week 1 Input: inputDate = 2026-07-15 Output: 29 Explanation: Day 196 of the year (approximately) is in week 29 Input: inputDate = null Output: null Explanation: Return null for null input
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

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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In