I am trying to calculate the amount of hours during the day and during the night using the sunrise and sunset times returned by the date_sunrise() and the date_sunset() functions. Admittedly though I'm not really sure how to go about doing that. I thought that making the sunrise and sunset times into variables and subtracting from each other might work, but I didn't take into consideration that subtracting hours is different than subtracting regular numbers, haha.
$lat = 38.7;
$long = -75;
$sunrise = (date_sunrise(time(),SUNFUNCS_RET_STRING,38.7,-75,75,-5));
$sunset = (date_sunset(time(),SUNFUNCS_RET_STRING,38.7,-75,75,-5));
//$light = $sunset - $sunrise; <-- Should return hours of daylight
//$dark = <-- Should return hours of nighttime
echo "Date: " . date("D M j Y");
echo "<br>Latitude: " . $lat;
echo "<br>Longitude: " . $long . "<br>";
echo "<br>Sunrise Time: " . $sunrise;
echo "<br>Sunset Time: " . $sunset . "<br>";
echo "<br>Hours of Light: " . $light;
echo "<br>Hours of Dark: " . $dark;
?>
This is what I have in terms of code so far. Everything else works fine, I just need to figure out the $light and $dark variables. Any assistance would be much appreciated!
expected result should be something like this
Thank you!