LifeAstroAPILifeAstroAPI

← Docs home

Calculate the tithi for any date and place with a panchang API

What a tithi is, why it changes with place and time, and how to get it with its end time, a whole month and festival dates in JavaScript.

A tithi is a lunar day in the Hindu calendar. It is the time the Moon takes to move 12 degrees further ahead of the Sun. A lunar month has 30 tithis in two halves, called pakshas. Shukla paksha is the waxing half: 15 tithis that end with Purnima, the full moon. Krishna paksha is the waning half: 15 tithis that end with Amavasya, the new moon. The names Pratipada, Dwitiya, Tritiya and so on repeat in each paksha. Only the 15th has two names. A tithi is not 24 hours long. It lasts roughly 19 to 26 hours, because the Moon's speed changes.

// Longitudes in degrees. Returns 0 to 29.
// 0 to 14 is Shukla paksha, 15 to 29 is Krishna paksha.
function tithiIndex(moonLon, sunLon) {
  const elongation = (((moonLon - sunLon) % 360) + 360) % 360;
  return Math.floor(elongation / 12);
}

The formula is short. The hard parts are the exact positions of the Sun and Moon, the moment a tithi ends, and local sunrise. This guide gets those from an API. Every response below is real output, trimmed by removing whole fields.

1. Why the tithi depends on place and time

A tithi starts and ends at one moment for the whole world. A calendar day does not. The Hindu day runs from sunrise to sunrise, and the tithi running at local sunrise gives the day its name. Sunrise is at a different moment in every city, so two cities can print different tithis for the same date.

On 10 January 2027, Shukla Dwitiya ended at 07:07:46 Indian time. Sunrise in Chennai was at 06:33:48, before that moment. Sunrise in New Delhi was at 07:14:57, after it. So that Sunday is Dwitiya in Chennai and Tritiya in New Delhi, in the same country and the same timezone.

Three things follow:

  • You need the latitude, longitude and timezone of the user, not of one fixed city.
  • The tithi can end in the middle of the day, so show its end time.
  • The date must be the user's local date.

2. Get the tithi for a date and place

/v1/panchang/tithi (10 credits) takes date, lat, lon and tz. It returns the tithi running at local sunrise on that date. This is New Delhi:

curl -H "Authorization: Bearer $LIFEASTRO_API_KEY" \
  "https://api.lifeastroapi.com/v1/panchang/tithi?date=2027-01-10&lat=28.6139&lon=77.209&tz=Asia/Kolkata"
{
  "date": "2027-01-10",
  "tz": "Asia/Kolkata",
  "index": 2,
  "name": "Tritiya",
  "paksha": "Shukla",
  "tithi_in_paksha": 3,
  "deity": "Gauri",
  "type": "Jaya",
  "end_jd": 2461416.6658723443,
  "end_local": "2027-01-11 09:28:51"
}
FieldMeaning
index0 to 29. 0 to 14 are Shukla paksha, 15 to 29 are Krishna paksha. 14 is Purnima and 29 is Amavasya.
name, pakshaWhat you show to the user.
tithi_in_paksha1 to 15 inside the paksha.
deity, typeThe presiding deity and the tithi group (Nanda, Bhadra, Jaya, Rikta or Purna).
end_localWhen the tithi ends, in the timezone you sent.
end_jdThe same moment as a Julian day number.

The same request for Chennai (lat=13.0827&lon=80.2707) returns a different tithi:

{
  "date": "2027-01-10",
  "index": 1,
  "name": "Dwitiya",
  "paksha": "Shukla",
  "end_local": "2027-01-10 07:07:46"
}

3. Show "until HH:MM" from end_local

end_local is a full date and time. In the New Delhi response it falls on the next day. Compare its date part with the request date before you print only the time.

const BASE = 'https://api.lifeastroapi.com';

async function getTithi({ date, lat, lon, tz }) {
  const q = new URLSearchParams({ date, lat: String(lat), lon: String(lon), tz });
  const res = await fetch(`${BASE}/v1/panchang/tithi?${q}`, {
    headers: { Authorization: `Bearer ${process.env.LIFEASTRO_API_KEY}` },
  });
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
  return res.json();
}

// "until 07:07", or "until 09:28 on 2027-01-11" when the tithi ends on a later date.
function untilLabel(t) {
  const [endDate, endTime] = t.end_local.split(' ');
  const hhmm = endTime.slice(0, 5);
  return endDate === t.date ? `until ${hhmm}` : `until ${hhmm} on ${endDate}`;
}

const cities = {
  'New Delhi': { lat: 28.6139, lon: 77.209, tz: 'Asia/Kolkata' },
  Chennai: { lat: 13.0827, lon: 80.2707, tz: 'Asia/Kolkata' },
};

for (const [name, place] of Object.entries(cities)) {
  const t = await getTithi({ date: '2027-01-10', ...place });
  console.log(`${name}: ${t.paksha} ${t.name} ${untilLabel(t)}`);
}

Output:

New Delhi: Shukla Tritiya until 09:28 on 2027-01-11
Chennai: Shukla Dwitiya until 07:07

After end_local the next tithi is running. If your screen shows the tithi "right now", compare the current time with end_local. /v1/panchang/advanced (30 credits) also returns a next_tithi object with its own start and end.

4. Tithi with sunrise in one call

/v1/panchang/basic (20 credits) returns the tithi with sunrise, sunset, moonrise and the other panchang elements (nakshatra, yoga, karana and weekday). With the Node SDK (npm install [email protected]):

import { LifeAstro } from 'lifeastroapi';

const astro = new LifeAstro({ apiKey: process.env.LIFEASTRO_API_KEY });
const chennai = { lat: 13.0827, lon: 80.2707, tz: 'Asia/Kolkata' };

const tithi = await astro.panchang.tithi({ ...chennai, date: '2027-01-10' }); // 10 credits
const day = await astro.panchang.basic({ ...chennai, date: '2027-01-10' });   // 20 credits

console.log(tithi.name, tithi.end_local);
console.log(day.sunrise_local, day.tithi.name, day.nakshatra.name);

Output:

Dwitiya 2027-01-10 07:07:46
2027-01-10 06:33:48 Dwitiya Shravana

The part of the basic response used here:

{
  "date": "2027-01-10",
  "sunrise_local": "2027-01-10 06:33:48",
  "sunset_local": "2027-01-10 17:58:46",
  "tithi": {
    "index": 1,
    "name": "Dwitiya",
    "paksha": "Shukla",
    "tithi_in_paksha": 2,
    "end_local": "2027-01-10 07:07:46"
  }
}

5. Get a whole month

For a calendar page, do not call the tithi endpoint 31 times. /v1/panchang/monthly (30 credits) returns one row per day with the tithi at sunrise.

import { LifeAstro } from 'lifeastroapi';

const astro = new LifeAstro({ apiKey: process.env.LIFEASTRO_API_KEY });
const delhi = { lat: 28.6139, lon: 77.209, tz: 'Asia/Kolkata' };

const month = await astro.panchang.monthly({ ...delhi, year: 2027, month: 1 }); // 30 credits

for (const d of month.days) {
  if (['2027-01-10', '2027-01-11', '2027-01-18', '2027-01-19', '2027-01-20'].includes(d.date)) {
    console.log(d.date, d.vara, d.tithi_paksha, d.tithi_name);
  }
}

Output:

2027-01-10 Sunday Shukla Tritiya
2027-01-11 Monday Shukla Tritiya
2027-01-18 Monday Shukla Dashami
2027-01-19 Tuesday Shukla Ekadashi
2027-01-20 Wednesday Shukla Trayodashi

One row, trimmed:

{
  "date": "2027-01-19",
  "vara": "Tuesday",
  "tithi_index": 10,
  "tithi_name": "Ekadashi",
  "tithi_paksha": "Shukla",
  "sunrise_local": "2027-01-19 07:14:09",
  "sunset_local": "2027-01-19 17:49:33"
}

Two things in that output surprise people. Tritiya appears on both the 10th and the 11th, because it was running at both sunrises. Dwadashi does not appear at all between Ekadashi and Trayodashi. It started after sunrise on the 19th and ended before sunrise on the 20th, so no day is named after it. Add include=sheet to the request and each day also lists every tithi that touches it, with end times. For 19 January:

{
  "date": "2027-01-19",
  "tithis": [
    {
      "name": "Ekadashi",
      "paksha": "Shukla",
      "end_local": "2027-01-19 07:50"
    },
    {
      "name": "Dwadashi",
      "paksha": "Shukla",
      "end_local": "2027-01-20 04:41"
    }
  ]
}

In the sheet, a tithi's index counts from 1 to 30. The tithi endpoints count from 0 to 29.

6. Festival dates follow from tithi rules

Most Hindu festivals and vrats (fasts) are defined by a tithi, and each has its own rule for the time of day at which that tithi must be running. Some use sunrise. Others use moonrise, the evening or midnight. /v1/festivals/month (20 credits) applies the rules and returns the dates with the windows that decided them. Sakat Chauth, a fast that ends when the Moon is seen, is kept on the day Krishna Chaturthi is running at moonrise. New Delhi, January 2027:

{
  "date": "2027-01-25",
  "name_en": "Sakat Chauth",
  "name_hi": "सकट चौथ",
  "tithi": "Chaturthi",
  "paksha": "Krishna",
  "observance": "moonrise",
  "windows": [
    {
      "label": "moonrise",
      "start": "21:12"
    },
    {
      "label": "tithi",
      "start": "08:11",
      "end": "06:01"
    }
  ]
}

At sunrise on 25 January the tithi in New Delhi is Krishna Tritiya. Chaturthi starts at 08:11 and is running at moonrise (21:12), so the fast is on the 25th. The window times are local times without a date. The end of the tithi window (06:01) is on the next morning.

Because the rule uses local sunrise and moonrise, the date can change with the city:

import { LifeAstro } from 'lifeastroapi';

const astro = new LifeAstro({ apiKey: process.env.LIFEASTRO_API_KEY });

const places = {
  'New Delhi': { lat: 28.6139, lon: 77.209, tz: 'Asia/Kolkata' },
  'New York': { lat: 40.7128, lon: -74.006, tz: 'America/New_York' },
};

for (const [name, place] of Object.entries(places)) {
  const { festivals } = await astro.festivals.month({ ...place, year: 2027, month: 1 }); // 20 credits
  const ekadashi = festivals.find((f) => f.name_en === 'Saphala Ekadashi');
  console.log(name, ekadashi.date, ekadashi.name_en);
}

Output:

New Delhi 2027-01-03 Saphala Ekadashi
New York 2027-01-02 Saphala Ekadashi

7. Common mistakes

  • Using the UTC date. new Date().toISOString().slice(0, 10) is the date in UTC. Early in the morning in India it is still yesterday there. Build the date in the user's timezone:
// The calendar date where the user is, as YYYY-MM-DD.
const localDate = (tz, now = new Date()) =>
  new Intl.DateTimeFormat('en-CA', { timeZone: tz }).format(now);

const now = new Date('2027-01-09T20:30:00Z');
console.log(now.toISOString().slice(0, 10)); // UTC date
console.log(localDate('Asia/Kolkata', now));
console.log(localDate('America/New_York', now));
2027-01-09
2027-01-10
2027-01-09
  • Using one fixed city for everyone. Section 1 shows two Indian cities with different tithis on one date. Store each user's latitude, longitude and IANA timezone.
  • Ignoring the end time. "Dwitiya" alone is wrong for most of that day in Chennai. "Dwitiya until 07:07" is right.
  • Printing only the time of end_local. It can be on the next date. Check the date part.
  • Assuming one new tithi per day. A tithi can repeat on two dates or be skipped. Do not add 1 to yesterday's tithi. Ask for each date.
  • Leaving out the place. Without lat and lon the API answers HTTP 400:
{"error": {"code": "missing_param", "message": "lat and lon are required", "request_id": "73b9a2bc3b5ef7dd"}}

A tithi for one date and place never changes. Cache it per date and city, and every user in that city can share the result.

Next steps