PHP date_sunrise()Functions
PHP Date/Time Reference Manual
Examples
Returns the sunrise time today in Lisbon, Portugal:
<?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>Sunrise time: ");
echo(date_sunrise(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>Sunrise time: ");
echo(date_sunrise(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1));
?>
Run Example »
Definition and Usage
The date_sunrise() function returns the sunrise time for a specified date and location.
Tip:See thedate_sunset()function, which returns the sunset time for a specified date and location.
Syntax
date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);
| Parameter | Description |
|---|---|
| timestamp | Required. Specifies the timestamp of the date for which to calculate the sunrise time. |
| format |
Optional. Specifies how to return the result:
|
| latitude | Optional. Specifies the latitude of the location. North latitude is assumed by default. Therefore, to specify a southern latitude, a negative value must be passed. |
| longitude | Optional. Specifies the longitude of the location. East longitude is assumed by default. Therefore, to specify a western longitude, a negative value must be passed. |
| zenith | Optional. Defaults to date.sunrise_zenith. |
| gmtoffset | Optional. Specifies the difference between GMT and local time, in hours. |
Technical Details
| Return Value: | If successful, the sunrise time is returned in the specifiedformatformat. If it fails, FALSE is returned. |
|---|---|
| PHP Version: | 5+ |
| Changelog: | As of PHP 5.1.0, this function emits E_STRICT and E_NOTICE timezone errors. |
PHP Date/Time Reference Manual Other Extensions