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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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 Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.