PHP Tutorial - PHP date_sun_info() Function






Definition

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.

Syntax

PHP date_sun_info() Function has the following syntax.

date_sun_info(timestamp,latitude,longitude);

Parameter

ParameterIs RequiredDescription
timestampRequired.timestamp
latitudeRequired.Latitude in degrees
longitudeRequired.Longitude in degrees




Return

PHP date_sun_info() Function returns an array on success. FALSE on failure.

Example

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.





Example 2

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.