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
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 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.