Code covered by the BSD License  

Highlights from
Day Length

4.0 | 1 rating Rate this file 14 Downloads (last 30 days) File Size: 3 KB File ID: #20390 Version: 1.03
image thumbnail

Day Length


Travis Wiens (view profile)


21 Jun 2008 (Updated )

Calculates the length of daylight for any day and latitude

| Watch this File

File Information

Calculates the length of daylight for any day of the year and latitude.
This uses Herbert Glarner's formulae which do not take into account refraction, twilight, size of the sun, etc

An example is included

See for more details/

MATLAB release MATLAB 8.5 (R2015a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
13 Oct 2014 Chad Greene

Chad Greene (view profile)

This is a helpful function; thanks for sharing.

The input day format is somewhat non-user-friendly. The function header describes the input date as the "day of the year, counted starting with the day of the December solstice in the first year of a Great Year." To maintain Travis' functionality and get this function to work with Matlab's datenum format, add this to the beginning of the function:

if nargin>0 && any(Day>366)
[y,~,~] = datevec(Day);
Day = 11+datenum(Day)-datenum(y,1,1);

The above assumes that if any input date exceeds 366, it must be in datenum format. Then the function *approximates* day length assuming a static December solstice. Results will not be exact on the daily timescale, but should be sufficient to put multi-year data in datenum format in context with solar cycles.

Comment only
03 May 2013 amit kaldhone


17 Jul 2009 1.1

Removed GPL per Mathworks' requirements.

15 Jul 2015 1.03

Fixes bug for latitudes above the arctic circle.

Contact us