<p>Another way to do it is to compute the RA/Dec of the Sun, then use the algorithm from Meeeus' Astronomical Algorithms<sup>1,2</sup> to compute the rise and set times for a given RA/Dec.</p>
<p>Below is a the algorithm for the low precision Sun position algorithm provided in the Astronomical Almanac, it is accurate to 1 degree between 1950 and 2050.  And an implementation in JavaScript follows.</p>
<p><span class="math-container">\begin{align*}
n&amp;=jd-2451545.0
\\
L&amp;=280.460+0.9856474*n
\\
g&amp;=375.528+.9856003*n
\\
\lambda &amp;=L+1.915*\sin g+0.020*\sin(2*g)
\\
\beta&amp;=0.0
\\
\epsilon &amp;=23.439-0.0000004*n
\\
\tan \alpha &amp;=\frac{\cos(\epsilon)*\sin(\lambda)}{\cos(\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,
and <span class="math-container">$\delta$</span> is the Declination.
Implementation in Javascript:</p>
<pre><code>function sunPosition(jd)    {
    const torad=Math.PI/180.0;
    const n=jd-2451545.0;
    let L=(280.460+0.9856474*n)%360;
    let g=((375.528+.9856003*n)%360)*torad;
    if(L&lt;0){L+=360;}
    if(g&lt;0){g+=Math.PI*2.0;}

    const lamba=(L+1.915*Math.sin(g)+0.020*Math.sin(2*g))*torad;
    const beta=0.0;
    const eps=(23.439-0.0000004*n)*torad;
    let ra=Math.atan2(Math.cos(eps)*Math.sin(lamba),Math.cos(lamba));
    const dec=Math.asin(Math.sin(eps)*Math.sin(lamba));
    if(ra&lt;0){ra+=Math.PI*2;}
    return [ra/torad/15.0,dec/torad];
}
</code></pre>
<p>To compute the rise and set times:</p>
<p><span class="math-container">$$
\cos H_0 = \dfrac{\sin h_0 - \sin \varphi \sin \delta }{\cos \varphi \cos \delta}
$$</span>
If <span class="math-container">$\cos H_0$</span> &lt; -1 or &gt; 1, the point is either always above or below the horizon.
<span class="math-container">$$
\begin{align}
T &amp;= (jd-2451545.0)/36525.0
\\
\Theta_0 &amp;= 280.46061837+360.98564736629*(jd-2451545.0)+0.000387933T^2 - T^3/38710000.0
\end{align}
$$</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.<br>
<span class="math-container">$\delta$</span> Declination<br>
<span class="math-container">$L$</span> Longitude<br>
<span class="math-container">$\varphi$</span> Latitude<br>
<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.<br>
<span class="math-container">$\Theta_0$</span> Greenwich sidereal time at 0h for the day in question.</p>
<p>And this page has a JavaScript <a href="https://www.celestialprogramming.com/risesetalgorithm.html" rel="nofollow noreferrer">implementation to compute the Sun rise, set, and transit</a> using the algorithms above.</p>
<p>You might also be interested in the book &quot;Practical Astronomy with your Calculator or Spreadsheet&quot; by Peter Duffett-Smith and Jonathan Zwart.  It has similar algorithms, but is more specific to doing it with a spreadsheet.</p>
<hr />
<ul>
<li><sup>1</sup>Meeus, Jean, <a href="https://www.abebooks.com/9780943396354/Astronomical-Algorithms-Meeus-Jean-0943396352/plp" rel="nofollow noreferrer">Astronomical Algorithms</a> Willmann-Bell, 1991</li>
<li><sup>2</sup>see also Meeus, Jean, <a href="https://www.abebooks.com/9780943396354/Astronomical-Algorithms-Meeus-Jean-0943396352/plp" rel="nofollow noreferrer">Astronomical Formulae for Calculators</a> Willmann-Bell, 1988</li>
</ul>

CC BY-SA 4.0
2022-12-12T14:38:43.117Z
2022-12-12T21:44:42.023Z
2022-12-12T21:44:42.023Z
Greg Miller
<p>I finally found <a href="http://free-solutions.schleu.de/js/tool_rechner_sunset.html" rel="nofollow noreferrer">the source</a>, or at least something like the source I had once back then. So I got this to work again:</p>
<p><a href="https://i.sstatic.net/Hf6IX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Hf6IX.png" alt="Sunrise—sunset table" /></a></p>
<p>These are the formulas needed:</p>
<pre><code>E2 =DAYS(A2;DATE(YEAR(A2);1;0))
F2 =(12+0.1752*SIN(0.03343*E2+0.5474)+0.134*SIN(0.0182334*E2-0.1939)-C2/15+24*D2)/24
G2 =0.40954*SIN(0.0172*(E2-79.35))
H2 =ACOS((-0.0145-SIN(B2*PI()/180)*SIN(G2))/(COS(B2*PI()/180)*COS(G2)))/PI()
I2 =F2-H2/2
J2 =F2+H2/2
</code></pre>
<p><em>As per the source I took it from, this is imprecise ±5 minutes.</em></p>

CC BY-SA 4.0
2022-12-13T15:20:34.903Z
Your location in the spreadsheet is in the Indian Ocean, not mid Europe. It's close enough to the equator that days would be close to twelve hours year round. If your latitude is expressed in radians, it's an impossible latitude: can't be greater pi/2.
stretch
CC BY-SA 4.0
2022-12-13T12:28:50.770Z
2022-12-13T12:34:05.957Z
2022-12-13T12:34:05.957Z
Maron
<p>I am looking for a way to roughly calculate sunrise and sunset for a given lon/lat in mid Europe for each day of a year using a spreadsheet application. The thing doesn’t need to be very precise, but it should give a rough idea like when to switch on street lights—earlier in winter than in summer.</p>
<p>I have read various pages on that topic now, but they deal with the question in a more complicated (and surely, more precise) way than what I need. I have had such a spreadsheet in the past (which I did build myself), but I don’t have it anymore and the sources I used seem to have vanished from the internet.</p>
<p>What I want is to make a spread sheet with one row per day, where column</p>
<p>A = the date (here, input as spreadsheet date)<br />
B = lon (W is negative, E is positive)<br />
C = lat (S is negative, N is positive)<br />
D = time zone (here, input as spreadsheet time)</p>
<p>What I needed is two formulas,</p>
<p>E = true noon<br />
F = day length</p>
<p>so that I can get sunrise and sunset as</p>
<p>G = E - (F/2)<br />
H = E + (F/2)</p>
<p>I think in the spreadsheet I once had, it took two sine calculations and some constants to get this done.</p>
<p><a href="https://i.sstatic.net/fbzva.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fbzva.png" alt="Example spreadsheet" /></a></p>
<p>Please help me get this working again or to find the sources where it is explained.</p>

CC BY-SA 4.0
2022-12-12T10:15:22.933Z
Related: https://astronomy.stackexchange.com/a/39685/16685
PM 2Ring
CC BY-SA 4.0
2022-12-13T12:57:05.883Z
Why do you want to know sunrise / sunset for a point in the Indian Ocean (near Somalia), and why are you using the +1:00 timezone for it? Have you mixed up latitude & longitude?
PM 2Ring
CC BY-SA 4.0
2023-08-23T06:41:16.593Z
True, column labels are reversed here. The order is as from GPS, first value is N > 0, S < 0, second value is E > 0, W < 0.
Maron
<sunrise><sunset>
How to roughly calculate sunrise and sunset with a spreadsheet application
Maron
# How to roughly calculate sunrise and sunset with a spreadsheet application

(Asked by: username_0 on 2022-12-12)

I am looking for a way to roughly calculate sunrise and sunset for a given lon/lat in mid Europe for each day of a year using a spreadsheet application. The thing doesn’t need to be very precise, but it should give a rough idea like when to switch on street lights—earlier in winter than in summer.

I have read various pages on that topic now, but they deal with the question in a more complicated (and surely, more precise) way than what I need. I have had such a spreadsheet in the past (which I did build myself), but I don’t have it anymore and the sources I used seem to have vanished from the internet.

What I want is to make a spread sheet with one row per day, where column

A = the date (here, input as spreadsheet date)  
B = lon (W is negative, E is positive)  
C = lat (S is negative, N is positive)  
D = time zone (here, input as spreadsheet time)

What I needed is two formulas,

E = true noon  
F = day length

so that I can get sunrise and sunset as

G = E - (F/2)  
H = E + (F/2)

I think in the spreadsheet I once had, it took two sine calculations and some constants to get this done.

[![Example spreadsheet](https://i.sstatic.net/fbzva.png)](https://i.sstatic.net/fbzva.png)

Please help me get this working again or to find the sources where it is explained.

**Tags:** sunrise, sunset

> **Comments:**
> **username_1**: Related: https://astronomy.stackexchange.com/a/39685/16685  
> **username_1**: Why do you want to know sunrise / sunset for a point in the Indian Ocean (near Somalia), and why are you using the +1:00 timezone for it? Have you mixed up latitude & longitude?  
> **username_0**: True, column labels are reversed here. The order is as from GPS, first value is N > 0, S < 0, second value is E > 0, W < 0.  

---

## 2 answers

### Answer by username_2 on 2022-12-12. Score: 1

Another way to do it is to compute the RA/Dec of the Sun, then use the algorithm from Meeeus' Astronomical Algorithms1,2 to compute the rise and set times for a given RA/Dec.

Below is a the algorithm for the low precision Sun position algorithm provided in the Astronomical Almanac, it is accurate to 1 degree between 1950 and 2050. And an implementation in JavaScript follows.

\begin{align\*}
n&=jd-2451545.0
\\
L&=280.460+0.9856474\*n
\\
g&=375.528+.9856003\*n
\\
\lambda &=L+1.915\*\sin g+0.020\*\sin(2\*g)
\\
\beta&=0.0
\\
\epsilon &=23.439-0.0000004\*n
\\
\tan \alpha &=\frac{\cos(\epsilon)\*\sin(\lambda)}{\cos(\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,
and $\delta$ is the Declination.
Implementation in Javascript:

```
function sunPosition(jd)    {
    const torad=Math.PI/180.0;
    const n=jd-2451545.0;
    let L=(280.460+0.9856474*n)%360;
    let g=((375.528+.9856003*n)%360)*torad;
    if(L<0){L+=360;}
    if(g<0){g+=Math.PI*2.0;}

    const lamba=(L+1.915*Math.sin(g)+0.020*Math.sin(2*g))*torad;
    const beta=0.0;
    const eps=(23.439-0.0000004*n)*torad;
    let ra=Math.atan2(Math.cos(eps)*Math.sin(lamba),Math.cos(lamba));
    const dec=Math.asin(Math.sin(eps)*Math.sin(lamba));
    if(ra<0){ra+=Math.PI*2;}
    return [ra/torad/15.0,dec/torad];
}

```

To compute the rise and set times:

$$
\cos H\_0 = \dfrac{\sin h\_0 - \sin \varphi \sin \delta }{\cos \varphi \cos \delta}
$$
If $\cos H\_0$ < -1 or > 1, the point is either always above or below the horizon.
$$
\begin{align}
T &= (jd-2451545.0)/36525.0
\\
\Theta\_0 &= 280.46061837+360.98564736629\*(jd-2451545.0)+0.000387933T^2 - T^3/38710000.0
\end{align}
$$

\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  
$\varphi$ 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.

And this page has a JavaScript [implementation to compute the Sun rise, set, and transit](https://www.celestialprogramming.com/risesetalgorithm.html) using the algorithms above.

You might also be interested in the book "Practical Astronomy with your Calculator or Spreadsheet" by Peter Duffett-Smith and Jonathan Zwart. It has similar algorithms, but is more specific to doing it with a spreadsheet.

---

* 1Meeus, Jean, [Astronomical Algorithms](https://www.abebooks.com/9780943396354/Astronomical-Algorithms-Meeus-Jean-0943396352/plp) Willmann-Bell, 1991
* 2see also Meeus, Jean, [Astronomical Formulae for Calculators](https://www.abebooks.com/9780943396354/Astronomical-Algorithms-Meeus-Jean-0943396352/plp) Willmann-Bell, 1988


---

### Answer by username_0 on 2022-12-13. Score: 0

I finally found [the source](http://free-solutions.schleu.de/js/tool_rechner_sunset.html), or at least something like the source I had once back then. So I got this to work again:

[![Sunrise—sunset table](https://i.sstatic.net/Hf6IX.png)](https://i.sstatic.net/Hf6IX.png)

These are the formulas needed:

```
E2 =DAYS(A2;DATE(YEAR(A2);1;0))
F2 =(12+0.1752*SIN(0.03343*E2+0.5474)+0.134*SIN(0.0182334*E2-0.1939)-C2/15+24*D2)/24
G2 =0.40954*SIN(0.0172*(E2-79.35))
H2 =ACOS((-0.0145-SIN(B2*PI()/180)*SIN(G2))/(COS(B2*PI()/180)*COS(G2)))/PI()
I2 =F2-H2/2
J2 =F2+H2/2

```

*As per the source I took it from, this is imprecise ±5 minutes.*

> **Comments:**
> **username_3**: Your location in the spreadsheet is in the Indian Ocean, not mid Europe. It's close enough to the equator that days would be close to twelve hours year round. If your latitude is expressed in radians, it's an impossible latitude: can't be greater pi/2.  

---

