What I ended up using works to a degree, the sunset function seems to be the biggest problem. Although I checked with published sites that post these things as either a table or links to data they have been compiled by those in the industry of timekeeping, latitude longitude and elevation and all that sort of thing. The function takes lat/long zenith (usually 90 degrees) GMT or UTC offset and has a default for all time functions as below:
date.default_latitude "31.7667" PHP_INI_ALL Available since PHP 5.0.0.
date.default_longitude "35.2333" PHP_INI_ALL Available since PHP 5.0.0.
date.sunrise_zenith "90.83" PHP_INI_ALL Available since PHP 5.0.0.
date.sunset_zenith "90.83" PHP_INI_ALL Available since PHP 5.0.0.
date.timezone "" PHP_INI_ALL Available since PHP 5.1.0.
For the sunrise function here is the detail:
Description
mixed date_sunrise ( int timestamp [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]] )
date_sunrise() returns the sunrise time for a given day (specified as a timestamp) and location. The latitude, longitude and zenith parameters default to the date.default_latitude, date.default_longitude and date.sunrise_zenith configuration options, respectively.
The latitude defaults to North. So, if you want to specify a South value, you must pass a negative value. The same note applies to longitude, which defaults to East.
The gmt_offset parameter is specified in hours.
Table 1. format constants
constant description example
SUNFUNCS_RET_STRING returns the result as string 16:46
SUNFUNCS_RET_DOUBLE returns the result as float 16.78243132
SUNFUNCS_RET_TIMESTAMP returns the result as integer (timestamp) 1095034606
So Los Angeles California has a latitude of 34.3 N (not negative), with a longitude of 118.4 W (negative from default), and a GMT or UTC offset of 7 hours.
I might try using the zenith of 90.83 instead of 90, right now I am off by a douple of minutes on sunrise but up to an hour including daylight savings time which I test for as an option...not gonna test for the new Federal Law about what dates and all the changes go into effect and where, just that Arizona doesn't use it at all.
So with all that said here is how I got close with this problem but still perhaps not quite right.
city = $local;
$state = $stval;
//echo "$city,$state";
$now = date("g:i:A");
$host ="localhost";
$pass = "";
$database = "sunrise";
$user ="root";
$connection = mysql_connect($host,$user,$pass)
or die ("Could not connect to server!");
$db = mysql_select_db($database,$connection)
or die ("Could not select $database");
$query = "SELECT city,state,lat,lng,off FROM sunrise WHERE city = '$city' and state= '$state'";
$result = mysql_query($query)
or die ("Could not execute database query!");
while ($row = mysql_fetch_array($result)){
extract($row);
echo "<b>$city, $state</b> latitude $lat, longitude $lng, GMT Offset $off.<br><br>";
}
$lng =$lng*(-1);
if ($state =="Arizona"){
$off = $off+(1);
}
echo "Offset =";
echo "$off";
echo "<br>";
echo "The time is now ";
echo $now;
echo "<br>";
$dateNow = Date("U"); // Date in unix format
$dateFixed = $dateNow + (16*60*60); // Adds 16 hours to the current date
echo "The sunrise for $city $state is<br>";
echo Date("D M d Y", $dateFixed),' sunrise time: ' .date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $lng,90.83,$off*(-1));
echo"<br><br>and the sunset for tomorrow is:<br>";
echo Date("D M d Y", $dateFixed),' sunset time: ' .date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $lng*(-1), 90.83, $off);
Keep in mind this is for DST and not ST! The reason for checking for state of Arizona and subtracting one hour from the offset.