Dec 14, 2011
Sunset and Sunrise Time using PHP
PHP5 have few very interesting new functions, Using two of them you can create your own "Sunrise and Sunset Calculator" to Find sunrise and sunset for a location.Here are these functions:-
date_sunrise
date_sunrise — Returns time of sunrise for a given day and location.
date_sunset
date_sunset — Returns time of sunset for a given day and location.
Uses
echo date_sunrise(time(), SUNFUNCS_RET_STRING, 29.91999999999999, 73.880, 90, 5.5);
echo date_sunset(time(), SUNFUNCS_RET_STRING, 29.91999999999999, 73.880, 90, 5.5);
You must know the latitude and longitude of the place, to use these functions.Here in above example, 29.91999999999999 is latitude, 73.880 is longitude, 90 is Zenith, and 5.5 is gmtoffset.
So the format should be like this:-
echo date_sunrise(time(), format, latitude, longitude, zenith, gmtoffset);
echo date_sunset(time(), format, latitude, longitude, zenith, gmtoffset);
Labels: php, resource, Tutorials
By : Motyar+ @motyar