- Using Text Within date()
- Automatically Localizing Dates
- Manually Localizing Dates
- Using the Current Date the U.S./U.K./European Way
- Formatting a Specific Date
- Validating a Date
- Calculating a Relative Date
- Creating a Sortable Time Stamp
- Converting a String into a Date
- Determining Sunrise and Sunset
- Using Date and Time for Benchmarks
- Using Form Fields for Date Selection
- Create Self-updating Form Fields for Date Selection
- Calculating the Difference Between Two Dates
- Using GMT Date/Time Information
Determining Sunrise and Sunset
date_sunrise(time(), SUNFUNCS_RET_STRING, 48, 11.5, 90, 1); date_sunset(time(), SUNFUNCS_RET_STRING, 48, 11.5, 90, 1);
Depending on the current location and date, the times for sunrise and sunset can drastically vary. However, formulas exist for determining this value depending on latitude and longitude, and PHP has this functionality integrated into its core starting with PHP 5. All you are required to do is call date_sunrise() and date_sunset(). Both functions expect a number of parameters:
A time stamp (epoche value) of the date for which to determine the sunrise/sunset
The desired format for the return value: SUFUNCS_RET_DOUBLE returns the time as a float value (between 0 and 23.99), SUNFUNCS_RET_STRING returns it as a string (between 00:00 and 23:59), and SUNFUNCS_RET_TIMESTAMP returns an epoche value
The latitude (Northern latitude; use negative values for a Southern latitude)
The longitude (Eastern longitude; use negative values for a Western longitude)
The zenith of the sunrise (in degrees)
The offset (in hours) to Greenwich mean time (GMT)
So, the preceding code (in sun.php)calculates the sunrise and sunset for Munich, Germany, which resides at about 48° Northern latitude, 11° 30’ Eastern longitude, for the current day. I checked it: It worked!