The date_sun_info() function returns an array containing information about sunset/sunrise and twilight begin/end, for a specified day and location.
date_sunrise() function returns the sunrise time for a specified day and location. date_sunset() function returns the sunset time for a specified day and location.
PHP date_sun_info() Function has the following syntax.
date_sun_info(timestamp,latitude,longitude);
Parameter | Is Required | Description |
---|---|---|
timestamp | Required. | timestamp |
latitude | Required. | Latitude in degrees |
longitude | Required. | Longitude in degrees |
PHP date_sun_info() Function returns an array on success. FALSE on failure.
Return information about sunset/sunrise and twilight begin/end on 1st January, 2013, for latitude 21.0000, longitude 30.0000:
<?php
$sun_info=date_sun_info(strtotime("2013-01-01"),21.0000,30.0000);
foreach ($sun_info as $key=>$val){
echo "$key: " . date("H:i:s",$val) . "<br>";
}
?>
The code above generates the following result.
The following code shows how to get information about sunset/sunrise and twilight begin/end for latitude and longitude.
<?php
$sun_info=date_sun_info(strtotime("2013-01-01"),31,35);
foreach ($sun_info as $key=>$val){
echo "$key: " . date("H:i:s",$val) . "<br>";
}
?>
The code above generates the following result.