date_sunset in PHP

Syntax of date_sunset

mixed date_sunset(int timestamp[, int format[, float latitude[, float longitude
[, float zenith[, float gmt_offset]]]]])

Returns the time of the sunset for the day in timestamp; false on failure. The format parameter determines the format the time is returned as (with a default of SUNFUNCS_RET_STRING), while the latitude, longitude, zenith, and gmt_offset parameters provide a specific location. They default to values given in the PHP configuration options (php.ini). Parameters include:

SUNFUNCS_RET_STRING Returns the value as a string; for example, “19:02”
SUNFUNCS_RET_DOUBLE Returns the value as a float; for example, 19.033
SUNFUNCS_RET_TIMESTAMP Returns the value as a Unix epochal timestamp

Example of date_sunset in PHP

<?php

/* calculate the sunset time for Lisbon, Portugal
Latitude: 38.4 North
Longitude: 9 West
Zenith ~= 90
offset: +1 GMT
*/

echo date("D M d Y"). ', sunset time : ' .date_sunset(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, 1);

?>
Mon Dec 20 2004, sunset time : 18:13

Leave a Comment