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!

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

Contest Alert

🏆 #CodeEveryDay Mar/April 2026

Contest runs March 3 - April 30. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.