PHP date_sunset()Function
PHP Date/Time Reference Manual
Examples
Returns the sunset time in Lisbon, Portugal today:
<?php
// Lisbon, Portugal:
// Latitude: 38.4 North, Longitude: 9 West
// Zenith ~= 90, offset: +1 GMT
echo("Lisbon, Portugal: Date: " . date("D M d Y"));
echo("<br>Sunset time: ");
echo(date_sunset(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1));
?>
// Lisbon, Portugal:
// Latitude: 38.4 North, Longitude: 9 West
// Zenith ~= 90, offset: +1 GMT
echo("Lisbon, Portugal: Date: " . date("D M d Y"));
echo("<br>Sunset time: ");
echo(date_sunset(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1));
?>
Run example »
Definition and Usage
The date_sunset() function returns the sunset time for a specified date and location.
Tip:See alsodate_sunrise()function, which returns the sunrise time for the specified date and location.
Syntax
date_sunset(timestamp,format,latitude,longitude,zenith,gmtoffset);
| Parameter | Description |
|---|---|
| timestamp | Required. Specifies the date/time timestamp to calculate the sunset time. |
| format |
Optional. Specifies how to return the result:
|
| latitude | Optional. Specifies the latitude of the location. Default is north latitude. Therefore, to specify south latitude, a negative value must be passed. |
| longitude | Optional. Specifies the longitude of the location. Default is east longitude. Therefore, to specify west longitude, a negative value must be passed. |
| zenith | Optional. Defaults to date.sunset_zenith. |
| gmtoffset | Optional. Specifies the difference between GMT and local time, in hours. |
Technical Details
| Return value: | If successful, in the specifiedformatformat, the sunset time is returned. If it fails, FALSE is returned. |
|---|---|
| PHP Version: | 5+ |
| Changelog: | Since PHP 5.1.0, this function reports E_STRICT and E_NOTICE timezone errors. |
PHP Date/Time Reference Manual Other Extensions