Most "what is my zodiac sign" code is a lookup table: Aries from March 21 to April 19, Taurus from April 20, and so on. I shipped exactly that table in a compatibility quiz. Then I computed when the Sun actually crosses each 30 degree boundary for every year from 1950 to 2030, and the table turned out to be wrong for roughly 1 birth in 80.
This post is the measurement, the code, and the fix.
The Sun does not change sign on a fixed date
The tropical zodiac is just ecliptic longitude cut into twelve 30 degree slices, starting at the March equinox (0 degrees = start of Aries). The calendar year is not a whole number of days and leap years reset the drift every four years, so the moment the Sun reaches 0, 30, 60... degrees slides by about six hours a year and jumps back on leap years. Over 81 years the UTC date of each crossing covers two, sometimes three, calendar days.
Here is what I counted, 1950 to 2030, UTC date of the crossing versus the first day the usual table gives:
| Sign | Table starts | UTC crossing date (number of years) |
|---|---|---|
| Aries | Mar 21 | Mar 20 (59), Mar 21 (22) |
| Taurus | Apr 20 | Apr 19 (22), Apr 20 (59) |
| Gemini | May 21 | May 20 (25), May 21 (56) |
| Cancer | Jun 21 | Jun 20 (6), Jun 21 (68), Jun 22 (7) |
| Leo | Jul 23 | Jul 22 (42), Jul 23 (39) |
| Virgo | Aug 23 | Aug 22 (19), Aug 23 (62) |
| Libra | Sep 23 | Sep 22 (26), Sep 23 (55) |
| Scorpio | Oct 23 | Oct 22 (4), Oct 23 (69), Oct 24 (8) |
| Sagittarius | Nov 22 | Nov 21 (7), Nov 22 (70), Nov 23 (4) |
| Capricorn | Dec 22 | Dec 21 (41), Dec 22 (40) |
| Aquarius | Jan 20 | Jan 19 (7), Jan 20 (70), Jan 21 (4) |
| Pisces | Feb 19 | Feb 18 (38), Feb 19 (43) |
The Aries line is the striking one: in 59 of 81 years the Sun is already in Aries on March 20 (UTC), the day the table still calls Pisces. Since 2008 the March equinox has not once fallen on March 21 in UTC.
How many people does the table misfile?
For each boundary I took the gap, in hours, between the real crossing and midnight at the start of the table's first day, summed it over the twelve boundaries, and divided by the hours in a year. That is the share of births (assuming births are spread evenly over the clock) that the table puts in the wrong sign.
| Birth time zone | Wrong with the fixed table | Wrong with the computed rule below |
|---|---|---|
| UTC (London in winter) | 1.25 % | 0.82 % |
| UTC+1 (Paris in winter) | 1.31 % | 0.83 % |
| UTC-5 (New York in winter) | 1.10 % | 0.97 % |
| UTC-8 (Los Angeles in winter) | 1.14 % | 1.19 % |
| UTC+9 (Tokyo) | 2.04 % | 1.27 % |
Two things stand out. Tokyo gets the worst of it: a crossing at 18:00 UTC is already the next morning there, so the table is off by a full day more often. And no rule based on the date alone can go to zero. If you only know the day of birth and the crossing happens somewhere inside that day, you are guessing for those hours. With the crossing landing at a random time of day, that floor is about 6 hours per boundary, 72 hours a year, or 0.82 % of births. The computed rule reaches that floor for Europe and gains less for the Americas, where midnight UTC is mid-evening.
So the honest statement is: if your app asks for a date only, about 1 user in 100 to 120 sits on a day where the sign depends on the birth hour, and a fixed table adds avoidable errors on top of that.
Computing the Sun's longitude in a few lines
You do not need an ephemeris library to name a 30 degree sign. Jean Meeus, Astronomical Algorithms (chapter 25, low accuracy method), gives the Sun's longitude to about 0.01 degree:
const D = Math.PI / 180;
function sunLongitude(ms) {
// Julian centuries from J2000.0, using TT approximated as UTC + 69 s
const t = ((ms + 69e3) / 86400000 + 2440587.5 - 2451545) / 36525;
const L0 = 280.46646 + 36000.76983 * t + 0.0003032 * t * t; // mean longitude
const M = 357.52911 + 35999.05029 * t - 0.0001537 * t * t; // mean anomaly
const C = (1.914602 - 0.004817 * t - 0.000014 * t * t) * Math.sin(M * D)
+ (0.019993 - 0.000101 * t) * Math.sin(2 * M * D)
+ 0.000289 * Math.sin(3 * M * D); // equation of centre
const omega = 125.04 - 1934.136 * t;
const apparent = L0 + C - 0.00569 - 0.00478 * Math.sin(omega * D); // nutation + aberration
return ((apparent % 360) + 360) % 360;
}
To find the crossing itself, bisect on the signed distance to the target longitude, wrapped to plus or minus 180 so the 0/360 seam does not break the search:
function crossing(startMs, endMs, targetDeg) {
const f = ms => ((sunLongitude(ms) - targetDeg + 540) % 360) - 180;
let a = startMs, b = endMs;
for (let i = 0; i < 60; i++) {
const m = (a + b) / 2;
if (f(m) < 0) a = m; else b = m;
}
return new Date(a);
}
One trap I hit: my first search window was a fixed 5 days after "March 20 plus 30.44 days per sign". The Sun moves slower in July (Earth is near aphelion), so the summer crossings fell outside the window and the bisection silently returned the window edge: every Leo, Virgo and Libra crossing came out on the same day for 81 years. A window of minus 6 to plus 10 days around the estimate fixed it. If your counts look too clean, check the window.
Checking the formula against published times
Before trusting the counts I compared the computed equinoxes and solstices with the times published by the US Naval Observatory:
| Event | Published (UTC) | Computed (UTC) | Gap |
|---|---|---|---|
| March equinox 2024 | Mar 20 03:06 | 03:03 | 3 min |
| June solstice 2024 | Jun 20 20:51 | 20:48 | 3 min |
| December solstice 2024 | Dec 21 09:20 | 09:13 | 7 min |
| March equinox 2025 | Mar 20 09:01 | 08:50 | 11 min |
| June solstice 2025 | Jun 21 02:42 | 02:34 | 8 min |
| March equinox 2026 | Mar 20 14:46 | 14:37 | 9 min |
Within about 12 minutes. That moves a crossing to the wrong day only when it falls in the last few minutes before midnight, which is noise next to the hours the fixed table gets wrong.
The rule I switched to
The quiz now takes the date, places it at 12:00 UTC, computes the Sun's longitude there and takes Math.floor(longitude / 30):
const SIGNS = ["aries","taurus","gemini","cancer","leo","virgo",
"libra","scorpio","sagittarius","capricorn","aquarius","pisces"];
function signFromDate(y, m, d) {
return SIGNS[Math.floor(sunLongitude(Date.UTC(y, m - 1, d, 12)) / 30) % 12];
}
Noon UTC is the middle of the civil day for Europe and Africa, which is why the error drops to the floor there. If you know the user's time zone, use local noon instead. If you also ask for the birth hour, use the exact instant and the error disappears. If you ask for neither, consider telling users born on a crossing day that their sign depends on the hour, instead of pretending a table knows.
The quiz that prompted this is at zodily.com, and the method page lists what the score uses (two Sun signs, nothing else). The counts above come from running the two functions in this post over 1950 to 2030, 972 crossings in all.
Top comments (0)