rwxr--r--
/dev/blog

Bez Hermoso, Software Engineer @ Square

If you ever wondered how to retrieve the time of sunrise and sunset on a given date in PHP, date_sun_info got you covered:

<?php

date_sun_info($timestamp = strtotime('2016-04-10'), $lat = 10.3079, $lng = 124.0195);

// => [
//      "sunrise" => 1460237721,
//      "sunset" => 1460282077,
//      "transit" => 1460259899,
//      "civil_twilight_begin" => 1460236449,
//      "civil_twilight_end" => 1460283350,
//      "nautical_twilight_begin" => 1460234961,
//      "nautical_twilight_end" => 1460284838,
//      "astronomical_twilight_begin" => 1460233466,
//      "astronomical_twilight_end" => 1460286332,
//    ]

Available since PHP 5.1.2. See full documentation: function.date-sun-info.php

comments powered by Disqus