The date_sunset() function returns the time of sunset for a given day / location.
Syntax
date_sunset(timestamp,format,latitude,longitude,zenith,gmtoffset);
Parameters
timestamp − Timestamp of the day from which the sunrise time is taken.
format − Specifies how to return the result
SUNFUNCS_RET_STRING − returns the result as string.
SUNFUNCS_RET_DOUBLE − returns the result as float.
SUNFUNCS_RET_TIMESTAMP −returns the result as integer (timestamp)
latitude − specifies the latitude of the location. The latitude defaults to North. If you want to specify a South value, you must pass a negative value.
longitude − specifies the longitude of the location. The longitude defaults to East. If you want to specify a West value, you must pass a negative value.
zenith − Defaults to date.sunrise_zenith
gmtoffset − The difference between GMT and local time in hours.
Return
The date_sunset() function returns the time of the sunrise, in the specified format, on success. FALSE on failure.
Example
The following is an example −
<?php echo("Date: " . date("D M d Y") . "<br />"); echo(date_sunset(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1)); ?>
Output
Date: Wed Oct 10 2018 19:02
Example
Let us see another example −
<?php echo date("D M d Y"); echo("\nSunset time: "); echo(date_sunset(time(), SUNFUNCS_RET_STRING, 22.9564, 85.8531, 90, 5.45)); ?>
Output
Wed Oct 10 2018 Sunset time: 17:20