Tithi

Tithi Calculator: How It Works

From Sun-Moon angle to tithi name — the complete computation pipeline with interactive examples.

TathaAstu Team8 min read

A tithi calculator is about fifteen lines of arithmetic on top of an ephemeris. The interesting part is what happens at the edges.

The core calculation

Take the sidereal longitude of the Moon, subtract the sidereal longitude of the Sun, normalise into the range 0 to 360, then divide by 12. The integer part plus one is the tithi number.

The whole idea
elongation = (moon_longitude - sun_longitude) % 360
tithi_number = int(elongation / 12) + 1

# 1-15   Shukla paksha (waxing), 15 = Purnima
# 16-30  Krishna paksha (waning), 30 = Amavasya

Note that the ayanamsa cancels out — it is subtracted from both longitudes. Tithi is one of the few panchang quantities where the choice of ayanamsa does not affect the result. Nakshatra, which depends on the Moon's absolute sidereal longitude, is not so forgiving.

Finding the boundaries

Knowing the tithi at an instant is easy. Knowing when it started and ends is the useful part, and that requires solving for the time at which the elongation crosses a multiple of twelve degrees.

There is no closed form, because the Moon's angular velocity varies. In practice you search: evaluate the elongation at bracketing times and bisect until the crossing instant is located to the precision you need. A binary search converges quickly because elongation increases monotonically.

Why the boundaries change everything

Once you have start and end instants rather than a per-day label, three problems disappear at once.

  • A tithi that spans midnight is just an interval spanning midnight — no special case.
  • Kshaya, where a tithi touches no sunrise, is an interval that happens not to contain a sunrise. Still no special case.
  • Vriddhi, where a tithi touches two sunrises, is an interval that contains two. Again, nothing special.

Every one of those is a notorious source of bugs in engines that model tithis as day labels, and none of them requires any handling at all in an engine that models them as intervals.

The precision question

How precisely do you need the boundary? For displaying a daily panchang, the minute is plenty. For muhurat calculations, where a window may be minutes long and users make decisions on it, we compute to the second. Rounding to the nearest minute was a real correction we shipped after user feedback.

TithiPanchangEducation