Home >>PHP Date Time Functions >PHP date_sun_info() Function

PHP date_sun_info() Function

PHP date_sun_info() Function

PHP date_sun_info() function is used to returns an array containing information about sunset or sunrise and twilight begin or end, for a specified day and location.

Syntax:

  date_sun_info($timestamp, $latitude, $longitude);

Parameter Values

Parameter Description
timestamp This is a required parameter. This parameter defines a timestamp.
latitude This is a required parameter. This parameter defines the latitude in degrees.
longitude This is a required. This parameter defines the longitude in degrees.

Here is an exmaple of date_sun_info() function in PHP:

<html>
<body>
<?php
echo "<h3>Date: 01 Feb, 2020</h3>";
$sun_info=date_sun_info(strtotime("2020-02-01"),21.7679,78.8718);
foreach ($sun_info as $key=>$val)
  {
  echo "$key: " . date("H:i:s",$val) . "<br>";
  }
?>
</body>
</html>
Output:
Date: 01 Feb, 2020
sunrise: 01:22:33
sunset: 12:33:23
transit: 06:57:58
civil_twilight_begin: 00:59:21
civil_twilight_end: 12:56:36
nautical_twilight_begin: 00:32:35
nautical_twilight_end: 13:23:21
astronomical_twilight_begin: 00:06:04
astronomical_twilight_end: 13:49:52

Example 2

<html>
<body>
<?php
echo "<h3>Date: 1st January, 2020</h3>";
$sun_info=date_sun_info(strtotime("2020-01-01"),31.7667,35.2333);
foreach ($sun_info as $key=>$val)
  {
  echo "$key: " . date("H:i:s",$val) . "<br>";
  }
echo "<h3>Date: 10th June, 2020</h3>";
$sun_info=date_sun_info(strtotime("2020-06-10"),31.7667,35.2333);
foreach ($sun_info as $key=>$val)
  {
  echo "$key: " . date("H:i:s",$val) . "<br>";
  }
?>
</body>
</html>
Output:
Date: 1st January, 2020
sunrise: 04:38:52
sunset: 14:45:49
transit: 09:42:20
civil_twilight_begin: 04:12:08
civil_twilight_end: 15:12:33
nautical_twilight_begin: 03:41:46
nautical_twilight_end: 15:42:55
astronomical_twilight_begin: 03:12:03
astronomical_twilight_end: 16:12:37

Date: 10th June, 2020
sunrise: 02:32:58
sunset: 16:44:14
transit: 09:38:36
civil_twilight_begin: 02:04:59
civil_twilight_end: 17:12:13
nautical_twilight_begin: 01:30:45
nautical_twilight_end: 17:46:27
astronomical_twilight_begin: 00:53:50
astronomical_twilight_end: 18:23:23

No Sidebar ads