I'm looking for a formula that will return the number of hours per day given a specific location. I was thinking that can be calculated as a difference of sunrise and sunset, but I see that there are some other ways, like in this topic.

What is the best, fast and correct way to calculate this?

  • 2
    $\begingroup$ en.wikipedia.org/wiki/Sunrise_equation $\endgroup$ – John Rennie May 18 '12 at 13:50
  • $\begingroup$ en.wikipedia.org/wiki/Day_length - Do you need analytical solution? I think such function would be very complicated... $\endgroup$ – Pygmalion May 18 '12 at 16:38
  • $\begingroup$ @Pygmalion I need something that I can further program using simple math functions available in PHP. I have the lat/lng and the date as starting points and I need to calculate some monthly averages, while keeping the individual values also on daily basis. $\endgroup$ – Elzo Valugi May 18 '12 at 17:26
  • $\begingroup$ You can find declination formula needed in John's reference here en.wikipedia.org/wiki/Declination. Therefore the solution between Artic and Antartic circle is finalized. I am puzzled about the rest. $\endgroup$ – Pygmalion May 18 '12 at 17:50
  • $\begingroup$ jgiesen.de/daylight $\endgroup$ – anna v May 18 '12 at 18:41

I think that

provide enough information. You put the equation from the second link into the equation from the first link. You get hours by multiplying the positive solution $\omega_0$ by $2 \cdot \frac{24\text{h}}{2\pi}$. If the equation from the first link has no solution ($\tan\phi \cdot \tan\delta>1$ ), this means day is either $24\text{h}$ or $0\text{h}$ long.

As far as I checked equations' output, they seem to be consistent.

  • 1
    $\begingroup$ The interpretation that $\tan\phi \cdot \tan\delta>1$ means continual day was very helpful. I would add that $\tan\phi \cdot \tan\delta<-1$ means continual night. $\endgroup$ – Green Jun 15 '17 at 23:09

The approximations work very poorly for anything beyond mid latitudes. Why not use the exact solution which is actually not complicated? For the exact solution, calculate the hour angle between sunrise and sunset. The Day Length in hours is then equal to (https://www.quora.com/How-can-you-calculate-the-length-of-the-day-on-Earth-at-a-given-latitude-on-a-given-date-of-the-year):

Day Length (hours) = 2 * ha / 15, (equation 1)

where ha is the hour angle of sunrise (sunset) from noon and is equal to (http://www.jgiesen.de/astro/suncalc/calculations.htm):

ha = arccos (cos(90.833) /(cos(L)*cos(δ)) - tan(L)*tan(δ)). (equation 2)

This uses 90.833 as the zenith angle of the sun at sunrise/sunset (i.e., it takes into account a standard value of the refraction at sunrise/sunset for the entire world, which is of course only approximate), L is the latitude, δ is the solar declination. The fraction of daylight in the day at latitude L is then,

2 * ha / (15 * 24). (equation 3)

Equation 3 can be used to plot the day-night terminator.

Note, that when the term in the arccos in equation 2 is greater or lesser than 1.0, then there is either total day or total night depending on the value of the declination). As a guide, δ is zero at equinoxes, positive in the northern summer, and negative in the northern winter (see reference 1). Equation 3 applies for all latitudes and for all times!

There are many javascript librarires that calculate δ, and then use it to plot the day-night terminator on google, bing, openstreet, etc. maps. I frankly don't understand why they don't use the exact expression above, which is not any more complicated than the one they typically use that ignores atmospheric refraction altogether (which is not physical at all).

To prove the point I modified the terminator code for Leaflet written by Jorg Dietrich. An expert Javascript coder should optimize my code. Here is the link.

  • $\begingroup$ Note that we have MathJax here, so you can use equations rather than bolded text. See here for more details. $\endgroup$ – Kyle Kanos Mar 20 '17 at 9:56

Number of hours of sunlight on nth day of the year =

12+(Max hrs of sunlight -min hrs of sunlight in the year)/2 * sin[(2π/365)*(n-t) ] where t is that day that has 12 hours of sunlight.

  • $\begingroup$ Of course this formula is valid between Arctic and Antarctic circle $\endgroup$ – Pygmalion May 18 '12 at 16:55
  • $\begingroup$ I am actually interested in something that will work and above Arctic circle as I am in North Norway and the data is from here. $\endgroup$ – Elzo Valugi May 18 '12 at 17:24
  • 1
    $\begingroup$ @ElzoValugi Above the Arctic circle, the sun stays up 24 hours a day for several days. Do you want the answer "24" or do you want the number of hours the sun stays up total, something like "48" to mean "up for 48 hours in a row"? $\endgroup$ – barrycarter May 21 '17 at 15:11

I have done some number crunching and found an equation for this exact question. For the town I live in the equation is 730-198sin ((2Pit/365)+(Pi/2) For any given location the 730 is the average between the longest and shortest day in minutes. This number may vary just slightly. For the 198sin, the coefficient 198 is the difference between the longest and shortest day in minutes. The variable is t for days from the winter solstice (winter solstice is day 0). The remainder of the equation is just a constant.

  • 1
    $\begingroup$ You should include your reasonings and calculations here to improve your question. $\endgroup$ – rmhleo Jan 21 '16 at 14:51
  • $\begingroup$ wordpress.barrycarter.org/index.php/2012/02/13/… has a similar but not identical calculation for Albuquerque. The further north you are, the less accurate a simple sinusoidal approximation will be. $\endgroup$ – barrycarter May 21 '17 at 15:13

\begin{align}T_{0} &=\frac{T}{\pi}\arccos\left(\frac{\tan\varphi\sin\theta}{\sqrt{\tan^{2}\alpha+\cos^{2}\theta}}\right) \\ \textrm{daylength} &=\begin{cases} T-T_{0} & \frac{\pi}{2}\le\alpha\le3\frac{\pi}{2}\\ T_{0} & \textrm{otherwise} \end{cases}\end{align} where $T=24\ \textrm{hours}$, $\varphi$ is latitude, $θ = 23.4°$ is Earth's axial tilt, and $α$ is the angle from Sun to Earth, calibrated to zero when (Sun)-(Earth's South Pole)-(Earth's North Pole) are on the same plane. Conversion from $α$ to day in year can be done directly.


protected by Qmechanic Mar 20 '17 at 9:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.