We needed the length of the day, both sunrise to sunset and twilight to twilight for particular latitudes. Sun_info() is just the thing. We mistakenly thought 'transit' was this value, which it is not. Transit is the time of day the sun is at its zenith. To get length of day, one must perform math on the results of sun_info().

When doing math with time values, don't expect date() to do the conversion to hours:minutes:seconds. date() thinks the passed value is a time since the epoch. You will need to do your own conversion to hours:minutes:seconds, using something like the following:<?phpfunction hms($val) {// convert seconds to hours:minutes:seconds$v=$val;$h=intval($v/3600);$v-=($h*3600); // subtract hours$m=intval($v/60); $v-=($m*60); // subtract minutes$s=$v % 60; // seconds remainingif ($h<10) {$h="0".$h;}if ($m<10) {$m="0".$m;}if ($s<10) {$s="0".$s;}return $h.":".$m.":".$s;}?>

Regarding date_sunrise() and date_sunset(), these both return values without seconds and without correction for Daylight time. Whereas sun_info() handles seconds as well as Daylight time. It even handles dates prior to the epoch correctly as negative timestamps, at least as of php 5.2.12

For example, sun_info(strtotime('July 4, 1776'),47.3506,-122.6417) produces something like the following when using date_default_timezone_set('America/Los_Angeles') and date("H:i:s", $val)