The date_sun_info() function returns an array with information about sunset/sunrise and twilight begin/ end.
Syntax
date_sun_info(timestamp, latitude, longitude)
Parameters
timestamp − A timestamp. Required.
latitude − The latitude in degrees. Required
longitude − The longitude in degrees. Required
Return
The date_sun_info() function returns an array with information about sunset/sunrise and twilight begin/ end.
The structure of the array is detailed in the following list −
sunrise − The time of the sunrise (zenith angle = 90°35').
sunset − The time of the sunset (zenith angle = 90°35').
transit − The time when the sun is at its zenith, i.e. has reached its topmost point.
civil_twilight_begin − The start of the civil dawn (zenith angle = 96°). It ends at sunrise.
civil_twilight_end − The end of the civil dusk (zenith angle = 96°). It starts at sunset.
nautical_twilight_begin − The start of the nautical dawn (zenith angle = 102°). It ends at civil_twilight_begin.
nautical_twilight_end − The end of the nautical dusk (zenith angle = 102°). It starts at civil_twilight_end.
astronomical_twilight_begin − The start of the astronomical dawn (zenith angle = 108°). It ends at nautical_twilight_begin.
astronomical_twilight_end − The end of the astronomical dusk (zenith angle = 108°). It starts at nautical_twilight_end.
Example
The following is an example −
<?php $info = date_sun_info(strtotime("2018-09-23"), 31.7667, 35.2333); foreach ($info as $key => $val) { echo "$key: " . date("H:i:s", $val) . "\n"; } ?>
Output
sunrise: 03:28:06 sunset: 15:34:29 transit: 09:31:18 civil_twilight_begin: 03:03:51 civil_twilight_end: 15:58:44 nautical_twilight_begin: 02:35:30 nautical_twilight_end: 16:27:05 astronomical_twilight_begin: 02:06:54 astronomical_twilight_end: 16:55:41