<p>The rise and set equations below are from Astronomical Algorithms, and the approximate Sun position is from the Astronomical Almanac.  The rise/set algorithm works for any celestial object given it's Right Ascension and Declination.  So, for the Sun, you must first compute the RA/Dec of the Sun and use that in the rise/set algorithm.  The <span class="math-container">$h_0$</span> parameter accounts for the fact that Sun rise/set is defined by the upper limb of the Sun, and a standard atmospheric refraction model.  An implementation of the below algorithm, including Julian Date, Sun position, and rise and set is implemented here: <a href="https://www.celestialprogramming.com/risesetalgorithm.html" rel="nofollow noreferrer">Rise and Set Algorithm</a>.</p>
<p>Both algorithms require the <a href="https://en.wikipedia.org/wiki/Julian_day" rel="nofollow noreferrer">Julian Date</a> rather than a Gregorian Calendar Date.  Since almost all programming languages can supply the date as the number of seconds or milliseconds elapsed since Jan 1 1970 (Unix Time), the routines below convert between Unix Time and Julian Date.  The implementation is in JavaScript but will be trivial to convert to any other language.  Since JavaScript returns Unix Time in milliseconds, these functions use that, if you're language uses seconds instead, replace 86400000 below with 86400.  Other methods of computing the Julian Date are here: <a href="https://www.celestialprogramming.com/julian.html" rel="nofollow noreferrer">Julian Date Algorithms</a>.</p>
<pre><code>function JulianDateFromUnixTime(t){
    //Not valid for dates before Oct 15, 1582
    return (t / 86400000) + 2440587.5;
}

function UnixTimeFromJulianDate(jd){
    //Not valid for dates before Oct 15, 1582
    return (jd-2440587.5)*86400000;
}
</code></pre>
<p><strong>Now use <span class="math-container">$jd$</span> to compute the RA/Dec of the Sun:</strong></p>
<p>This algorithm for the Sun position is accurate to 1 degree between 1950 and 2050 according to the Astronomical Almanac.  If a higher precision is necessary (and it usually isn't), a method like <a href="https://github.com/gmiller123456/vsop87-multilang" rel="nofollow noreferrer">VSOP87</a> can be used.
<span class="math-container">$$
\begin{align*}
n&amp;=jd-2451545.0
\\
L&amp;=280.460+0.9856474n
\\
g&amp;=375.528+.9856003n
\\
\lambda &amp;=L+1.915 \sin g+0.020 \sin 2g
\\
\beta&amp;=0.0
\\
\epsilon &amp;=23.439-0.0000004n
\\
\cos\lambda \tan \alpha &amp;=\cos\epsilon \sin\lambda
\\
\sin \delta &amp;=\sin\epsilon \sin \lambda
\end{align*}
$$</span></p>
<p>Where <span class="math-container">$\lambda$</span> is the ecliptic longitude, <span class="math-container">$\beta$</span> is the ecliptic latitude (always 0), <span class="math-container">$\alpha$</span> is the Right Ascension,
<span class="math-container">$\delta$</span> is the Declination.  And <span class="math-container">$ jd $</span> is the Julian Date.</p>
<p><strong>Now use <span class="math-container">$\alpha$</span> and <span class="math-container">$\delta$</span> to compute the rise and set times:</strong></p>
<p>The algorithm below is from Meeus' Astronomical Algorithms, that book considers longitudes to be negative to the East, which is opposite of modern definitions, so set <span class="math-container">$L = -L$</span> for most applications.</p>
<p><span class="math-container">$$
\cos H_0 = \dfrac{\sin h_0 - \sin \phi \sin \delta }{\cos \phi \cos \delta} \ $$</span></p>
<p>If <span class="math-container">$\cos H_0$</span> &lt; -1 or &gt; 1, the point is either always above or below the horizon.</p>
<p><span class="math-container">$T=(jd-2451545.0)/36525.0 $</span></p>
<p><span class="math-container">$\Theta_0 = 280.46061837+360.98564736629*(jd-2451545.0)+0.000387933T^2 - T^3/38710000.0$</span></p>
<p><span class="math-container">$$
\begin{cases}
transit &amp; \dfrac{\delta + L - \Theta_0 }{360^{\circ}} \\
\\
rise &amp; transit - \dfrac{H_0}{360^{\circ}} \\
\\
set &amp; transit + \dfrac{H_0}{360^{\circ}}
\end{cases}
$$</span></p>
<p><span class="math-container">$jd$</span> is the Julian Date for the date in question.</p>
<p><span class="math-container">$\delta$</span> Declination.</p>
<p><span class="math-container">$L$</span> Longitude.</p>
<p><span class="math-container">$\phi$</span> Latitude.</p>
<p><span class="math-container">$h_0$</span> Apparent rise or set angle, -0.8333 for the Sun, +0.125 for the Moon, and -0.5667 for most other objects.</p>
<p><span class="math-container">$\Theta_0$</span> Greenwich sidereal time at 0h for the day in question.</p>
<p>The results <span class="math-container">$transit$</span>, <span class="math-container">$rise$</span>, <span class="math-container">$set$</span>, are in fractions of a day, so multiply by 24 to get the time in hours.  If any of them are greater than 1, or less than 0, add or subtract 1 to bring it in the range from 0 to 1.  They will be in the UTC time zone, so conversion to the local time zone may be desired.</p>
<p><strong>Final:</strong></p>
<p>Since the Sun moves throughout the day, it may be desired to produce a more accurate result by recomputing everything again, but using the JD for the rise, set or transit time.  In the Arctic Circle, it's possible <span class="math-container">$H_0$</span> will indicate no rise or set for the first iteration, but the Sun may move to a position where it does rise or set, so it may be desired to retry values throughout the day.</p>

CC BY-SA 4.0
2023-01-18T15:08:55.177Z
2023-01-18T15:08:55.177Z
Greg Miller
<p>What is the mathematical tool that enable to compute time of sunrise and time of sunset at a specific geographical location in the same part of a year, say given month and day exactly?</p>
<p>I have noticed that the time of sunrise and the time of sunset is the same every year in a given month and day, say February 4th for example (at a specific geographical location of course).</p>
<p>Thank you.</p>

CC BY-SA 4.0
2023-01-17T22:22:29.490Z
This is given in detail on Wikipedia [Sunrise equation](https://en.wikipedia.org/wiki/Sunrise_equation)
James K
CC BY-SA 4.0
2023-01-18T06:54:19.943Z
I have some approximate sunrise / sunset calculations in [this answer](https://astronomy.stackexchange.com/a/39685/16685). I also have more precise calculations, but the mathematics is more complicated, as you can see in this [related post](https://astronomy.stackexchange.com/a/49546/16685).
PM 2Ring
CC BY-SA 4.0
2023-01-18T06:55:24.487Z
However, even the best predictions can only give an approximation to the true sunrise / sunset time because of the effects of the weather on atmospheric refraction.
PM 2Ring
CC BY-SA 4.0
2023-01-18T07:09:49.057Z
Also related: https://astronomy.stackexchange.com/q/47872/16685
PM 2Ring
<sunrise><sunset>
math tool to compute time of sunrise and sunset
Jen
# math tool to compute time of sunrise and sunset

(Asked by: username_0 on 2023-01-17)

What is the mathematical tool that enable to compute time of sunrise and time of sunset at a specific geographical location in the same part of a year, say given month and day exactly?

I have noticed that the time of sunrise and the time of sunset is the same every year in a given month and day, say February 4th for example (at a specific geographical location of course).

Thank you.

**Tags:** sunrise, sunset
> **Comments:**
> **username_1**: This is given in detail on Wikipedia [Sunrise equation](https://en.wikipedia.org/wiki/Sunrise_equation)  
> **username_2**: I have some approximate sunrise / sunset calculations in [this answer](https://astronomy.stackexchange.com/a/39685/16685). I also have more precise calculations, but the mathematics is more complicated, as you can see in this [related post](https://astronomy.stackexchange.com/a/49546/16685).  
> **username_2**: However, even the best predictions can only give an approximation to the true sunrise / sunset time because of the effects of the weather on atmospheric refraction.  
> **username_2**: Also related: https://astronomy.stackexchange.com/q/47872/16685  

---

## 1 answers

### Answer by username_3 on 2023-01-18. Score: 3 | Accepted answer

The rise and set equations below are from Astronomical Algorithms, and the approximate Sun position is from the Astronomical Almanac.  The rise/set algorithm works for any celestial object given it's Right Ascension and Declination.  So, for the Sun, you must first compute the RA/Dec of the Sun and use that in the rise/set algorithm.  The $h_0$ parameter accounts for the fact that Sun rise/set is defined by the upper limb of the Sun, and a standard atmospheric refraction model.  An implementation of the below algorithm, including Julian Date, Sun position, and rise and set is implemented here: Rise and Set Algorithm.
Both algorithms require the Julian Date rather than a Gregorian Calendar Date.  Since almost all programming languages can supply the date as the number of seconds or milliseconds elapsed since Jan 1 1970 (Unix Time), the routines below convert between Unix Time and Julian Date.  The implementation is in JavaScript but will be trivial to convert to any other language.  Since JavaScript returns Unix Time in milliseconds, these functions use that, if you're language uses seconds instead, replace 86400000 below with 86400.  Other methods of computing the Julian Date are here: Julian Date Algorithms.
function JulianDateFromUnixTime(t){
    //Not valid for dates before Oct 15, 1582
    return (t / 86400000) + 2440587.5;
}

function UnixTimeFromJulianDate(jd){
    //Not valid for dates before Oct 15, 1582
    return (jd-2440587.5)*86400000;
}

Now use $jd$ to compute the RA/Dec of the Sun:
This algorithm for the Sun position is accurate to 1 degree between 1950 and 2050 according to the Astronomical Almanac.  If a higher precision is necessary (and it usually isn't), a method like VSOP87 can be used.
$$
\begin{align*}
n&=jd-2451545.0
\\
L&=280.460+0.9856474n
\\
g&=375.528+.9856003n
\\
\lambda &=L+1.915 \sin g+0.020 \sin 2g
\\
\beta&=0.0
\\
\epsilon &=23.439-0.0000004n
\\
\cos\lambda \tan \alpha &=\cos\epsilon \sin\lambda
\\
\sin \delta &=\sin\epsilon \sin \lambda
\end{align*}
$$
Where $\lambda$ is the ecliptic longitude, $\beta$ is the ecliptic latitude (always 0), $\alpha$ is the Right Ascension,
$\delta$ is the Declination.  And $ jd $ is the Julian Date.
Now use $\alpha$ and $\delta$ to compute the rise and set times:
The algorithm below is from Meeus' Astronomical Algorithms, that book considers longitudes to be negative to the East, which is opposite of modern definitions, so set $L = -L$ for most applications.
$$
\cos H_0 = \dfrac{\sin h_0 - \sin \phi \sin \delta }{\cos \phi \cos \delta} \ $$
If $\cos H_0$ < -1 or > 1, the point is either always above or below the horizon.
$T=(jd-2451545.0)/36525.0 $
$\Theta_0 = 280.46061837+360.98564736629*(jd-2451545.0)+0.000387933T^2 - T^3/38710000.0$
$$
\begin{cases}
transit & \dfrac{\delta + L - \Theta_0 }{360^{\circ}} \\
\\
rise & transit - \dfrac{H_0}{360^{\circ}} \\
\\
set & transit + \dfrac{H_0}{360^{\circ}}
\end{cases}
$$
$jd$ is the Julian Date for the date in question.
$\delta$ Declination.
$L$ Longitude.
$\phi$ Latitude.
$h_0$ Apparent rise or set angle, -0.8333 for the Sun, +0.125 for the Moon, and -0.5667 for most other objects.
$\Theta_0$ Greenwich sidereal time at 0h for the day in question.
The results $transit$, $rise$, $set$, are in fractions of a day, so multiply by 24 to get the time in hours.  If any of them are greater than 1, or less than 0, add or subtract 1 to bring it in the range from 0 to 1.  They will be in the UTC time zone, so conversion to the local time zone may be desired.
Final:
Since the Sun moves throughout the day, it may be desired to produce a more accurate result by recomputing everything again, but using the JD for the rise, set or transit time.  In the Arctic Circle, it's possible $H_0$ will indicate no rise or set for the first iteration, but the Sun may move to a position where it does rise or set, so it may be desired to retry values throughout the day.


---

