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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.