Hours of light per day based on latitude/longitude formula 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?
 A: I think that


*

*Sunrise equation and 

*Declination of the Sun
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.
A: 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.       
A: 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.
A: 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.  
A: \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.
