Determining the relative position of the sun from any location on Earth at any time of the year involves a series of calculations, many of which are approximations.  The first step to understanding these is to summarize a few basic quantities.

Declination of the Sun ($\theta_{d}$) – This is the angle between the Earth’s axis of rotation and the plane normal to a line connecting the centers of the Earth and Sun.

A simple approximation for the declination (in degrees) is:

$\theta_{d}&space;=\frac{23.45\pi&space;}{180}\sin&space;\left&space;(&space;2\pi&space;\frac{\left&space;(&space;284+n\right&space;)&space;}{365}\right&space;)$ ,  where $n$ is the day of year.

Hour Angle ($\theta_{hr}$) – This is the angle of the Sun in its apparent orbit through the sky.  By convention it is defined to zero at solar noon (when the Sun reaches its highest point in the sky each day).  Since it takes approximately 24 hours for the Earth to rotate each day, the hour angle changes by 15 degrees each hour (360°/24).

Solar vs. Standard Time – While local time is synchronous across a single time zone, solar time is defined as the relative position of the sun to an observation point.  Therefore, solar time will vary by longitude across the time zone at a given local time.  What is known as the “Equation of Time” is used to calculate the difference between solar and local time as a function of location and time of year.

The equation of time ($E_{qt}$) can be approximated with a series of equations depending on the day of the year:

For n=1 to 106: $E_{qt}=-14.2\sin&space;\left&space;(&space;\frac{\pi&space;\left&space;(&space;n+7&space;\right&space;)}{111}&space;\right&space;)$

For n=107 to 166 $E_{qt}=4.0\sin&space;\left&space;(&space;\frac{\pi&space;\left&space;(&space;n-106&space;\right&space;)}{59}&space;\right&space;)$

For n =167 to 246 $E_{qt}=-6.5\sin&space;\left&space;(&space;\frac{\pi&space;\left&space;(&space;n-166&space;\right&space;)}{80}&space;\right&space;)$

For n = 247 to 365 $E_{qt}=16.4\sin&space;\left&space;(&space;\frac{\pi&space;\left&space;(&space;n-247&space;\right&space;)}{113}&space;\right&space;)$

Using this approximation the solar time ($T_{solar}$) in hours is calculated as:

$T_{solar}=T_{local}+\frac{E_{qt}}{60}+\frac{Long_{sm}-Long_{local}}{15}$, where $Long_{sm}$ is the longitude of the standard meridian of the observer’s time zone (degrees) and $Long_{local}$ is the longitude of the observer (degrees).

The hour angle (radians) can be calculated as a function of solar time as:

$\theta_{hr}&space;=\pi&space;\frac{12-T_{solar}}{12}$ .

The cosine of the solar zenith angle can then be calculated as:

$cos(\theta_{Z})&space;=&space;sin(\lambda)&space;sin(\theta_{d}&space;)&space;+&space;cos(\lambda&space;)cos(\theta_{d})cos(\theta_{hr})$, where $\lambda$ is the latitude of the observer.