I'm trying to code a piece of software which will calculate some times for me that would greatly help me in my day to day but none of my formulae work if the sun doesn't go at least 18 degrees below the horizon.

In this case, I have different formulae to use but I need to program the software to be able to use this other formula on these days. I have no way of determining the maximum the sun will depress below the horizon on any specific day or location.

I am not an expert in any sense of the word in astronomy and literally only know what is relevant to what I need, but I think what I am trying to ask is if it is possible to determine the if the minimum solar elevation / altitude angle is less than -18 degrees on a day / location.

I have attempted to search but was unsuccessful and am even unsure if what I am asking for is even possible.

Thanks for any help!

  • 1
    $\begingroup$ In other words, you're looking for the days where astronomical twilight never ends and it's never dark enough (in theory) to see 6th magnitude stars at the zenith? $\endgroup$
    – user21
    Jul 9, 2018 at 3:09
  • 2
    $\begingroup$ As noted in my astronomy.stackexchange.com/questions/14492/… the lowest altitude a celestial object reaches is abs(lat+dec)-90 degrees, where lat is the latitude in degrees (negative for southern hemisphere), and dec is the declination in degrees. You can solve this to see what solar declinations make that number greater than -18. However, this doesn't really answer your question: you can calculate solar declination to high precision, but I'd like to provide a simple approximation if I actually "answer" this question. $\endgroup$
    – user21
    Jul 9, 2018 at 14:48
  • $\begingroup$ What's your formula do with changes in latitude? $\endgroup$ Jul 9, 2018 at 17:08
  • $\begingroup$ @CarlWitthoft If that was directed at me, the formula actually includes latitude as a parameter. $\endgroup$
    – user21
    Jul 10, 2018 at 15:04
  • $\begingroup$ I don't know the formula, but astropy can calculate the values. You can extract the logic from the source code if you need to. $\endgroup$ Jul 12, 2018 at 11:06

2 Answers 2


An approximation of the Sun’s declination for a certain date is:

sin δ = 0.39795 ⋅ cos [ 0.98563 ⋅ ( N – 173 ) ]

where N is the number of days since January 1.

That, combined with the formula given by @user21, viz.:

$ a_{min} = \lvert \phi + \delta \rvert - 90° $

will give you the dates where the Sun is at least 18° under the horizon.

(Oddly enough, a simple instrument, invented by the Greeks almost 2,000 years ago and perfected by the Muslims over the next few centuries, the astrolabe, would give you the answer almost instantly, without having to do any calculations. Below is a photo of one I made in brass.)

Brass astrolabe, home-made by Pierre Paquette, 2020


First see the plethora of diverse answers to Where can I find the positions of the planets, stars, moons, artificial satellites, etc. and visualize them?

Then if you can use Python or would like to learn, consider using Skyfield for everything!

Also have a look at Astronomical Algorithms in this very long answer:

This is something you'll have to dig into a bit, but if you like to program, it may be exactly what you're looking for. The Gaisma website is one of my favorites on the internet - easy to use and presents a bunch of information in easy-to-understand graphics. Click around!

I believe that this site uses algorithms from the collection found at this NOAA site. Click around there as well. They provide Excel spreadsheets which contain the algorithms and other resources. The "main" resource is a collection of algorithms published in the book Astronomical Algorithms - Jean Meeus. Search the books title and you can find that there are many similarly titled books. I'd recommend going to a library if possible, because it's (in my opinion) always good to go to libraries. However parts of these can be found on-line. For example, a few pages shown from the book Astronomical Formulae for Calculators (1988) include an interesting table of contents.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .