PHP date_sun_info() function

PHP date_sub() function
PHP date_sunset() function

In this article, you will learn how to get the sun information in PHP. The date_sun_info() function returns the sunrise/sunset or twilight start/end of the specified date.

What is the syntax of the date_sun_info() function in PHP?

date_sun_info(timestamp, latitude, longitude)
ParameterDescription
timestampTimestamp to get the information of – Required
latitudeLatitude of the location in degrees – Required
longitudeLongitude of the location in degrees – Required
PHP date_sun_info() method

Examples of the date_sun_info() function

Example 1. In this example, we return the information about the sunrise/sunset and start/end of twilight for the specified date.

<?php
$info=date_sun_info(strtotime("2014-11-15"),31.7667,35.2333);
foreach ($info as $key=>$val)
  {
  echo "$key: " . date("H:i:s",$val) . " ";
  }
?>
PHP date_sub() function
PHP date_sunset() function
en English
X
Scroll to Top