PHP Tutorial - PHP date_sunrise() Function


The date_sunrise() function returns the sunrise time for a specified day and location.

date_sunset() function returns the sunset time for a specified day and location.


PHP date_sunrise() Function has the following syntax.



ParameterIs RequiredDescription
timestampRequired.timestamp of the day from which the sunrise time is taken
formatOptional.returned value format
latitudeOptional.Latitude of the location. Defaults to North. To specify a value for South, pass in a negative value
longitudeOptional.Longitude of the location. Defaults to East. To specify a value for West, pass in a negative value
zenithOptional.Defaults to date.sunrise_zenith
gmtoffsetOptional.Difference between GMT and local time in hours

Format available values.

SUNFUNCS_RET_STRINGreturns the result as string. e.g. 15:46) (This is default)
SUNFUNCS_RET_DOUBLEreturns the result as float. e.g. 12.123456)
SUNFUNCS_RET_TIMESTAMPreturns the result as integer (timestamp). e.g. 1211233211)


PHP date_sunrise() Function returns the time of the sunrise, in the specified format, on success. FALSE on failure.


Return the sunrise time for Lisbon, Portugal today:

    // Lisbon, Portugal:
    // Latitude: 38.4 North, Longitude: 9 West
    // Zenith ~= 90, offset: +1 GMT
echo("Lisbon, Portugal: Date: " . date("D M d Y"));
echo("Sunrise time: ");

The code above generates the following result.