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

PHP date_sunset() Function

PHP date_sunset() Function

PHP date_sunset() function is used to get the sunset time for a specified day and location. It returns the sunset time of the place based on the given latitude, longitude, zenith, and gmt offset of that place.

Syntax:

date_sunset(timestamp, format, latitude, longitude, zenith, gmtoffset);

Parameter Values

Parameter Description
timestamp This is a required parameter. This parameter defines the timestamp of the day from which the sunset time is taken.
format This is an optional parameter. This parameter defines how to return the result.
latitude This is an optional parameter. This parameter defines the latitude of the location.
longitude This is an optional parameter. This parameter defines the longitude of the location.
zenith This is an optional parameter. This parameter defines zenith value.
gmtoffset This is an optional parameter. This parameter defines the difference between GMT and local time in hours.

Here is an example of date_sunset() function in PHP:

<html>
<body>
<?php
echo "Sunset time: ";
echo date_sunset(time());
?>

</body>
</html>
Output:
Sunset time: 15:11

Example 2:

<html>
<body>
<?php
echo "Date: ".date("D M d Y");
echo "<br>";
echo "Sunset time in India today: ";
echo(date_sunset(time(),SUNFUNCS_RET_STRING,28,-77,90,-5.5));
?>
</body>
</html>
Output:
Date: Fri Jan 31 2020
Sunset time in India today: 17:14

No Sidebar ads