Dr Phill's Science Made Simple

Sun and Moon Rise and Set Calculations

How to calculate the times of sunrise, sunset, moonrise and moonset for any location on Earth. There are some complications particularly in the polar regions. Depending upon location and time of month or year each event can occur 0, 1 or even 2 times in a day.

The following values are required for all calculations:

Sunrise and Sunset

To calculate the times of sunrise and sunset, first of all calculate the time of solar noon \(T = J_s + E\).

Where \(E\) is the equation of time offset for the day.

It also requires the angular offset from the Sun's centre to the upper limb \(\alpha = -0.833^{\circ}\).

The algorithm is:

  1. Calculate the ecliptic longitude \(\lambda\) of the Sun at time \(T\);
  2. Calculate the declination \(\delta\) of the Sun at time \(T\);
  3. Calculate the hour angle \(\omega\);
  4. Calculate the Sunrise and sunset times.

The hour angle is the angular offset from the Sun position at solar noon to the Sun position at sunrise and sunset. The hour angle is \(90^{\circ}\) on the equator and everywhere at the equinoxes.

$$\cos\omega = \frac{\sin\alpha - \sin\phi\sin\delta}{\cos\phi\cos\delta}$$

If \(|\cos\omega| > 1\) then sunrise and sunset do not occur.

The times of sunrise and sunset can now be calculated. The times are in Terrestial Time and need to be converted to local time for the location.

$$T_{sunrise} = T - \omega/2\pi$$ $$T_{sunset} = T + \omega/2\pi$$


The results of the calcualtions are accurate to a minute or so as long as the latitude is not too hight. Accuracy can be improved by iteration.

Note that the location longitude and the longitude of the Sun are not involved in the calculation.

Iteration is performed on the sunrise and sunset times separately. The initial calculation made by computing the declination of the Sun at solar noon for the day. For each of sunrise and sunset, compute the time using the solar declination at solar noon. Then repeat the calculation using the computed sunrise or sunset time until the difference between iterations is accurate enough. It typically takes about two iterations.