Calculate the number of days from today until the next occurrence of a birthday given a birth date. If today is the birthday, return 0. Always return the days to the next future birthday.

Examples:

Input: birthDate = Date.newInstance(1990, 7, 15), today = Date.newInstance(2025, 7, 1) Output: 14 Explanation: Birthday is July 15, which is 14 days from July 1 Input: birthDate = Date.newInstance(2000, 3, 1), today = Date.newInstance(2025, 3, 1) Output: 0 Explanation: Today is the birthday Input: birthDate = Date.newInstance(1985, 1, 10), today = Date.newInstance(2025, 12, 20) Output: 21 Explanation: Next birthday is January 10 of the following year
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 November 2026 (Nov 16–30)Sponsored by FLXBL

Contest runs November 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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In