Given two dates (inclusive), count the number of weekend days (Saturday and Sunday) that fall within the range. Return null if either input is null. Return 0 if endDate is before startDate. Both the start and end dates are included in the range.

Examples:

Input: startDate = 2026-01-05 (Monday), endDate = 2026-01-11 (Sunday) Output: 2 Explanation: The range includes Saturday 2026-01-10 and Sunday 2026-01-11 Input: startDate = 2026-01-03 (Saturday), endDate = 2026-01-04 (Sunday) Output: 2 Explanation: Both days are weekend days Input: startDate = 2026-01-05 (Monday), endDate = 2026-01-09 (Friday) Output: 0 Explanation: No weekend days in this weekday-only range Input: startDate = 2026-01-10, endDate = 2026-01-05 Output: 0 Explanation: End date before start date returns 0 Input: startDate = null, endDate = 2026-01-05 Output: null Explanation: Null input returns 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 June 2026

Contest runs June 1 - 30. Complete challenges to climb the leaderboard!

Only the 30 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In