Given a Date, return the Western zodiac sign for that date based on its month and day. Return null for null input.
The zodiac date ranges are:
- Aries: March 21 - April 19
- Taurus: April 20 - May 20
- Gemini: May 21 - June 20
- Cancer: June 21 - July 22
- Leo: July 23 - August 22
- Virgo: August 23 - September 22
- Libra: September 23 - October 22
- Scorpio: October 23 - November 21
- Sagittarius: November 22 - December 21
- Capricorn: December 22 - January 19
- Aquarius: January 20 - February 18
- Pisces: February 19 - March 20
Examples:
Input: d = Date.newInstance(2026, 1, 15)
Output: 'Capricorn'
Explanation: January 15 falls in the Capricorn range (Dec 22 - Jan 19)
Input: d = Date.newInstance(2026, 7, 4)
Output: 'Cancer'
Explanation: July 4 falls in the Cancer range (Jun 21 - Jul 22)
Input: d = Date.newInstance(2026, 11, 30)
Output: 'Sagittarius'
Explanation: November 30 falls in the Sagittarius range (Nov 22 - Dec 21)
Input: d = Date.newInstance(2026, 3, 21)
Output: 'Aries'
Explanation: March 21 is the first day of Aries
Input: d = null
Output: null
Explanation: Null input returns null
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 September 2026 (Sep 1–15)Sponsored by FLXBL
Contest runs September 1 - 15. Complete challenges to climb the leaderboard!
1st & 2nd: Salesforce certification exam voucher — see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.