Quick Reference
The PHP date_sun_info() function returns an array containing information about sunset/sunrise and twilight begin/end, for a specified day and location.
<?php
echo '<h3>Marina del Rey, CA: January 1, 2013</h3>';
$sun_info = date_sun_info(strtotime('2013-01-11'), 36.627861, -121.811211);
foreach ($sun_info as $key => $val) {
echo $key . ': ' . date('H:i:s',$val) . '<br>';
}
?>
Output
Marina del Rey, CA: January 1, 2013
sunrise: 15:19:15
sunset: 01:11:54
transit: 20:15:34
civil_twilight_begin: 14:51:03
civil_twilight_end: 01:40:06
nautical_twilight_begin: 14:19:09
nautical_twilight_end: 02:11:59
astronomical_twilight_begin: 13:48:02
astronomical_twilight_end: 02:43:07
Syntax
date_sun_info(timestamp, latitude, longitude)
Parameters
Parameter | Description |
---|---|
timestamp | Specifies a timestamp (required) |
latitude | Specifies the latitude in degrees (required) |
longitude | Specifies the longitude in degrees (required) |
PHP Notes:
- When using PHP, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
- Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.