PHP date_sunrise() Function

Example

Return the sunrise time for today in Shanghai, China:

<?php
// Shanghai, China:
// Latitude: 31.22 North, Longitude: 121.47 West
// Zenith ~= 90, Offset: +8 GMT
echo("Shanghai, China: Date: " . date("D M d Y"));
echo("<br>Time of sunrise:");
echo(date_sunrise(time(), SUNFUNCS_RET_STRING, 31.22, 121.47, 90, 8));
?>

Run Example

Definition and Usage

The date_sunrise() function returns the sunrise time at a specified date and location.

Tip:See also date_sunset() Function, returns the sunset time at a specified date and location.

Syntax

date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);
Parameters Description
timestamp Required. Specifies the timestamp of the date and time to calculate the sunrise time.
format

Optional. Specifies how to return the result:

  • SUNFUNCS_RET_STRING (returns the result as a string, for example, 16:46) (default)
  • SUNFUNCS_RET_DOUBLE (returns the result as a floating-point number, for example, 16.78243132)
  • SUNFUNCS_RET_TIMESTAMP (returns the result as an integer (timestamp), for example, 1095034606)
latitude Optional. Specifies the latitude of the location. Default is North Latitude. To specify South Latitude, please pass a negative value.
longitude Optional. Specifies the longitude of the location. Default is East Longitude. To specify West Longitude, please pass a negative value.
zenith Optional. Default is date.sunrise_zenith.
gmtoffset Optional. Specifies the difference between GMT and local time in hours.

Technical Details

Return Value: If successful, it returns the sunrise time in the specified format. If it fails, it returns FALSE.
PHP Version: 5+
Update Log: Starting from PHP 5.1.0, the function reports time zone errors E_STRICT and E_NOTICE.