India API

Docs › Dates and calendars

Sun and moon API

Sunrise, sunset, twilight, moonrise and the moon's phase for any date and place.

The astronomy of a day without the almanac: sunrise, sunset, solar noon and day length; civil, nautical and astronomical twilight; moonrise and moonset; the moon's phase, how much of it is lit and its age; and the next new, first quarter, full and last quarter moons. Computed with the same code as the panchang, and checked against NASA's JPL ephemeris.

Base URL https://api.dharun.devNo API key600 requests a minuteThis page as Markdown

Sun and moon for a date

GET/v1/sun-moon/{date}

For a pincode, a latitude and longitude, or (by default) New Delhi. A twilight time is null where the sun does not sink that far, and moonrise or moonset is null on the day each month the moon does not rise or set. The phase names a principal phase (new moon, first quarter, full moon, last quarter) for the whole date it falls on.

ParameterDescription
datepath, requiredYYYY-MM-DD, 1900 to 2100, or today.
pincodequeryIndian pincode of the place.
latqueryLatitude, -66 to 66, if no pincode.
lngqueryLongitude, if no pincode.
tzqueryIANA time zone for the times. Default Asia/Kolkata.

curl

curl "https://api.dharun.dev/v1/sun-moon/2026-10-14?pincode=600001"

JavaScript

const response = await fetch("https://api.dharun.dev/v1/sun-moon/2026-10-14?pincode=600001");
const body = await response.json();
if (!response.ok) throw new Error(body.error.message);
console.log(body.data);

Python

import requests

response = requests.get("https://api.dharun.dev/v1/sun-moon/2026-10-14?pincode=600001", timeout=10)
body = response.json()
if not response.ok:
    raise RuntimeError(body["error"]["message"])
print(body["data"])

Response, with lists and long text shortened

{
  "data": {
    "place": {
      "latitude": 13.0949,
      "longitude": 80.287,
      "timeZone": "Asia/Kolkata",
      "pincode": "600001",
      "name": "Chennai"
    },
    "date": "2026-10-14",
    "sun": {
      "sunrise": "2026-10-14T05:59:05+05:30",
      "sunset": "2026-10-14T17:50:35+05:30",
      "solarNoon": "2026-10-14T11:54:55+05:30",
      "dayLengthMinutes": 711.5,
      "noonElevation": 68.74,
      "civilTwilight": {
        "dawn": "2026-10-14T05:37:41+05:30",
        "dusk": "2026-10-14T18:11:59+05:30"
      },
      "nauticalTwilight": {
        "dawn": "2026-10-14T05:12:53+05:30",
        "dusk": "2026-10-14T18:36:46+05:30"
      },
      "astronomicalTwilight": {
        "dawn": "2026-10-14T04:48:09+05:30",
        "dusk": "2026-10-14T19:01:30+05:30"
      }
    },
    "moon": {
      "moonrise": "2026-10-14T08:55:43+05:30",
      "moonset": "2026-10-14T20:26:23+05:30",
      "phase": "waxing crescent",
      "illumination": 13,
      "ageDays": 3.6,
      "nextPhases": {
        "newMoon": "2026-11-09T12:32:14+05:30",
        "firstQuarter": "2026-10-18T21:42:39+05:30",
        "fullMoon": "2026-10-26T09:41:43+05:30",
        "lastQuarter": "2026-11-02T01:58:29+05:30"
      }
    }
  },
  "meta": {
    "note": "Computed from the positions of the Sun and the Moon (NREL SPA and Meeus). Sunrise, sunset and twilight agree with the JPL ephemeris to within seconds; moonrise …"
  }
}

Using an AI assistant? Connect the MCP server and it can call this API by itself.