How can I compute sunrise/sunset times?

skiphoppy picture skiphoppy · Apr 1, 2009 · Viewed 30.9k times · Source

I like to keep track of sunrise and sunset times. For the past couple of years I've been doing this with a small program written with a popular library for my favorite programming language. The last two months I've been keeping track of these times more regularly than usual, and I happened to notice that on the day of the equinox the sunrise time jumped eight minutes as compared to the day before! I knew this was impossible and compared with NOAA, finding out that my rise and set times had been off for several days and in fact seemed to be off by about a minute for most of the year.

At this point, I'd like to just implement the calculations myself. What algorithms or formulas are available to do this computation?

Answer

user57365 picture user57365 · Apr 1, 2009

You may consider reading Wikipedia's article on sunrise equations. The lead paragraph gives the equation:

where:

  • ωo is the hour angle in degrees at either sunrise (when negative value is taken) or sunset (when positive value is taken) in degree (°)
  • φ is the latitude of the observer on the Earth in degrees
  • δ is the sun declination in degrees