Given a date, return the week of the month it falls in, using a 1-indexed scheme where days 1 through 7 are week 1, days 8 through 14 are week 2, days 15 through 21 are week 3, and so on. Return 0 if the input date is null.
Examples:
Input: inputDate = Date.newInstance(2026, 9, 14)
Output: 2
Explanation: Day 14 falls in days 8-14, which is week 2
Input: inputDate = Date.newInstance(2026, 9, 1)
Output: 1
Explanation: Day 1 falls in days 1-7, which is week 1
Input: inputDate = Date.newInstance(2026, 9, 7)
Output: 1
Explanation: Day 7 is the last day of week 1
Input: inputDate = Date.newInstance(2026, 9, 8)
Output: 2
Explanation: Day 8 is the first day of week 2
Input: inputDate = Date.newInstance(2026, 9, 30)
Output: 5
Explanation: Day 30 falls in days 29-35, which is week 5
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.