Calculator

Day Length Calculator

Enter a date, latitude, and longitude to see exactly how many hours of daylight that location gets — and whether days are getting longer or shorter.

Fill in date, latitude, and longitude

Why day length changes with latitude

The closer a location sits to the equator, the less its day length varies across the year — a city near the equator gets close to 12 hours of daylight almost every day. The closer to a pole, the more extreme the swing, up to literal 24-hour days in summer and 24-hour nights in winter within the polar circles. This calculator shows the exact day length for whatever coordinates you enter, plus the change from the day before, so you can see that seasonal drift directly rather than just estimating it.

Want the actual sunrise and sunset clock times behind this calculation, not just the total? See the Sunrise & Sunset Calculator.

Related

Related tools

function julianDate(y,m,d){ if(m <= 2){ y -= 1; m += 12; } const A = Math.floor(y/100); const B = 2 - A + Math.floor(A/4); return Math.floor(365.25*(y+4716)) + Math.floor(30.6001*(m+1)) + d + B - 1524.5; } function computeSunTimes(year, month, day, lat, lon){ const J_date = julianDate(year, month, day) + 0.5; // approx noon JD for the date const n = J_date - 2451545.0 + 0.0008; const Jstar = n - (lon/360); const Mdeg = (357.5291 + 0.98560028 * Jstar) % 360; const M = Mdeg * Math.PI/180; const C = 1.9148*Math.sin(M) + 0.0200*Math.sin(2*M) + 0.0003*Math.sin(3*M); let lambdaDeg = (Mdeg + C + 180 + 102.9372) % 360; const lambda = lambdaDeg * Math.PI/180; const Jtransit = 2451545.0 + Jstar + 0.0053*Math.sin(M) - 0.0069*Math.sin(2*lambda); const sinDelta = Math.sin(lambda) * Math.sin(23.4397*Math.PI/180); const delta = Math.asin(sinDelta); const latRad = lat * Math.PI/180; const cosOmega0 = (Math.sin(-0.83*Math.PI/180) - Math.sin(latRad)*Math.sin(delta)) / (Math.cos(latRad)*Math.cos(delta)); if(cosOmega0 > 1) return {polarNight:true}; if(cosOmega0 < -1) return {midnightSun:true}; const omega0 = Math.acos(cosOmega0) * 180/Math.PI; const Jrise = Jtransit - omega0/360; const Jset = Jtransit + omega0/360; function jdToDate(jd){ const unixMs = (jd - 2440587.5) * 86400000; return new Date(unixMs); } return { sunrise: jdToDate(Jrise), sunset: jdToDate(Jset), transit: jdToDate(Jtransit), daylightHours: (omega0/180)*24 }; } const dlDate = document.getElementById('dlDate'); const dlLat = document.getElementById('dlLat'); const dlLon = document.getElementById('dlLon'); const dlResult = document.getElementById('dlResult'); function render(){ if(!dlDate.value || dlLat.value === '' || dlLon.value === ''){ dlResult.innerHTML = 'Fill in date, latitude, and longitude'; return; } const [y,m,d] = dlDate.value.split('-').map(Number); const lat = parseFloat(dlLat.value), lon = parseFloat(dlLon.value); if(Math.abs(lat) > 90 || Math.abs(lon) > 180){ dlResult.innerHTML = 'Latitude must be -90 to 90, longitude -180 to 180'; return; } const today = computeSunTimes(y,m,d,lat,lon); if(today.polarNight){ dlResult.innerHTML = '
0 hours — polar night on this date at this location.
'; return; } if(today.midnightSun){ dlResult.innerHTML = '
24 hours — midnight sun on this date at this location.
'; return; } const prevDate = new Date(y,m-1,d); prevDate.setDate(prevDate.getDate()-1); const prev = computeSunTimes(prevDate.getFullYear(), prevDate.getMonth()+1, prevDate.getDate(), lat, lon); const hours = Math.floor(today.daylightHours); const minutes = Math.round((today.daylightHours - hours)*60); let diffStr = ''; if(!prev.polarNight && !prev.midnightSun){ const diffMin = Math.round((today.daylightHours - prev.daylightHours)*60); diffStr = diffMin >= 0 ? `+${diffMin} min vs. yesterday` : `${diffMin} min vs. yesterday`; } dlResult.innerHTML = `
Daylight${hours}h ${minutes}m
` + (diffStr ? `
Change${diffStr}
` : ''); } [dlDate, dlLat, dlLon].forEach(el => el.addEventListener('input', render));