home / moonrise

The rising and setting of the Sun and Moon

Fill in the boxes below and click 'calculate' to generate a table showing sunrise, set and twilight times and the lunar rise and set times for your latitude and time zone. See the notes below and the javascript code in this page for details of the calculation method. This page is self-contained. Save it to your computer for quick reference.

Year : Answers believed to be useable for 50 years either side of 2000
Month : No error checking!
Day :
Longitude : Decimal degrees west longitudes must be negative
Time Zone : Decimal hours west of or 'behind' Greenwich negative.
UK BST is +1 hour, check any daylight saving corrections for your time zone.
Latitude : Decimal degrees south negative
Number of days : How many lines in the table?
Click to run : Use reset to clear table
Results :
Copy and paste!

Notes

This page describes an algorithm that will enable you to calculate the time of Moon rise and set and Sun rise and set, as well as the twilight times, for any latitude on the Earth's surface. The algorithm uses quadratic interpolation based on hourly altitudes of the Sun and the Moon. The algorithm presented here will warn you if the Moon or Sun remains above or below the horizon all day (a definite possibility above latitudes of 66.5 degrees North), or if the object does not rise or set within the day chosen (the Moon will exhibit this behaviour on one day in each lunar cycle). The algorithm is taken from Montenbruck and Pfleger's Astronomy on the Personal Computer second English edition, section 3.8.

In the implementation of the algorithm on this page, I have used approximate routines to calculate the coordinates of the Sun and Moon. You can choose latitudes where the program will predict a very short day when the Sun really remains below the horizon all day - this inaccuracy affects latitudes close to 67.43 degrees North, and you can imagine a 'fuzzy zone' around the Earth at this latitude (and a mirror image one in the South) where the program may be in error. The situation for moonrise and set is more complex as the 'lunar arctic circle' changes as the Moon's orbit changes its orientation. I suspect that more accurate position routines and better approximations for topocentric parallax, refraction and the diameter of the Sun and Moon would shrink this 'fuzzy zone', at the cost of increased complexity. The program will give meaningful results above latitude 70 degrees where methods based on iteration cannot.

The problem

The rising and setting of the Sun and Moon is defined here to be the instant when the upper limb of the object is seen to cross a mathematically flat horizon by an observer at sea level. Real observing situations on land rarely approach this idealised model, and for my uses calculating rise and set times to the nearest minute or so is fine.

The following factors need to be addressed when calculating rise and set times

Approximate corrections

In Montenbruck and Pfleger's approximate implementation, the last three points above boil down to subtracting a single correction term from the geocentric altitude of the Moon or Sun when looking for rise or setting events.

The large difference between the Moon and the Sun correction reflects the much larger parallax effect on Moon positions - roughly 1 degree for the Moon compared to 9 arc seconds for the Sun.

Different methods

Below is a list of possible methods for calculating rise and set times for the Sun and Moon, in order of increasing complexity.

I used the 'single position and calculate as for star' method on a programmable calculator - the results for the Sun at moderate latitudes were 20 minutes or so wrong. Given the state of the local horizon, this was not much of a problem. This 'method' was very poor for the Moon, almost worse than guessing from the number of days since New Moon.

The 'trial and improvement' method with allowance for refraction, parallax and disc size is much better, and can give good results for the Sun for latitudes below 65N. The method will mostly converge after a few iterations..

Tral and improvement methods get fiddly in situations where the object remains above or below the horizon for a number of days, or where the object does not set one day or the next.

A table based method could be very simple - just calculate the altitude of the Moon for each minute of the day and find when the altitude changes sign. There is your rising or setting event.

This simple table based method could detect the 'always above the horizon' or 'always below the horizon' situations as the (corrected) altitude would never change sign over the day. The method could also cope with the Moon missing a rise or set each lunar cycle, but 'grazing' situations, where the Sun never quite dips below the horizon, would be more difficult as there would be no sign change in the altitudes. A real program based on this system would be really slow, requiring at worst case 1440 calculations of altitude for each object for each day.

Interpolation based methods use a shorter table of altitudes - in my implementation we use a table with a maximum of 25 rows - and fit a quadratic function to each set of three altitudes in turn. We then use some GCSE algebra to find the times when the quadratic crosses the X axis - has zero altitude - and these times are candidates for a rising or setting event. This system can also deal with the situation when the rising and setting occur within the hour - the quadratic then has two zeros. Finally, if the two zeros are the same, then there must be a 'grazing' event in that interval, and the algorithm can detect the event.

Interpolation algorithm

The steps in the algorithm are

  1. Calculate the sine of the altitude (corrected for refraction, parallax and the limb radius) for the first three hours in the day. Using the sine of the altitude saves some calculation and means that the values will always be within the range +1 to -1.
  2. Save sign of the altitude at 0h
  3. Take the values of the sine of the altitude for each set of three consecutive hours, correct for the refraction, parallax and fit a quadratic curve through these three points. See Montenbruck and Pfleger for algebra.
  4. Calculate the 'discriminant' for the quadratic, and classify as
  5. If neither rise nor set flag is set, then warn user that object is 'always above' or 'always below' horizon depending on the sign of the altitude in step 2, and move onto next object or quit.
  6. Print rise and set times, or message if one event missing in current day.
  7. Move onto next object or quit.

References

Oliver Montenbruck and Thomas Pfleger,
Astronomy on the Personal Computer
Springer
1994, 3rd edition
ISBN 3-540-63521-1

Section 3.8 of this book is the basis of the QBASIC listing here. I have translated the PASCAL routines into QBASIC one by one. This book does not contain an exhaustive explanation of the quadratic fit method, and the test data the authors provide will not test all branches of the code. This book comes with a software disc with all the PASCAL routines - but does not cover all the ground in, say, Meeus' Astronomical Algorithms.

Sky and Telescope's software pages contain listings in 'spaghetti basic' that implement a similar method for the Sun and the Moon - there is a clever fix used to avoid re-calculating positions for the Sun and Moon up to 12 times each day at the cost of some increase in the 'fuzzy zone' when the programs may predict a Sunrise and set when there is none. The links below are to the BASICA listings.

http://www.skyandtelescope.com/wp-content/uploads/sunup.bas

http://www.skyandtelescope.com/wp-content/uploads/moonup.bas

Seidelmann, P. Kenneth (ed)
Explanatory Supplement to the Astronomical Almanac
University Science Books
1992, completely revised
ISBN 0-935702-68-7

Definitive reference on all aspects of the ephemeris and associated calculations. No hostages taken, no example calculations and modern vectoral notation used throughout. Sections 9.311 (p484) and 9.33 (p486) present the iterative algorithm for Sunrise for moderate latitudes.

Duffett-Smith, Peter
Practical Astronomy with your calculator
Cambridge University Press
3rd edition 1988
ISBN 0-521-35699-7

Good treatment of the basics of coordinate systems. Presents the formulas for rise and set time of a star, and presents an interesting linear interpolation scheme for Moonrise.


Keith Burnett, originally written Jan 2003