Given two dates, calculate the number of complete weeks between them. The order of the dates does not matter - always return a non-negative result. Use integer division to drop any remaining days that do not form a complete week. Return null if either date is null.
Examples:
Input: startDate = 2026-01-01, endDate = 2026-01-15
Output: 2
Explanation: 14 days between the dates equals exactly 2 complete weeks
Input: startDate = 2026-01-01, endDate = 2026-01-20
Output: 2
Explanation: 19 days between the dates equals 2 complete weeks with 5 extra days
Input: startDate = 2026-03-01, endDate = 2026-01-01
Output: 8
Explanation: 59 days between the dates equals 8 complete weeks with 3 extra days
Input: startDate = null, endDate = 2026-01-01
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 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.