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 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.