PHP date_sunset() Function
In this chapter you will learn:
- Definition for PHP date_sunset() Function
- Syntax for PHP date_sunset() Function
- Parameter for PHP date_sunset() Function
- Return value from PHP date_sunset() Function
- Example - Return the sunset time for Lisbon, Portugal today
Definition
The date_sunset() function returns the sunset time for a specified day and location.
date_sunrise() function returns the sunrise time for a specified day and location.
Syntax
PHP date_sunset() Function has the following syntax.
date_sunset(timestamp,format,latitude,longitude,zenith,gmtoffset);
Parameter
Parameter | Is Required | Description |
---|---|---|
timestamp | Required. | Timestamp of the day from which the sunset time is taken |
format | Optional. | Format to return the result: |
latitude | Optional. | Latitude of the location. Defaults to North. To specify a value for South, pass in a negative value |
longitude | Optional. | Longitude of the location. Defaults to East. To specify a value for West, pass in a negative value |
zenith | Optional. | Defaults to date.sunset_zenith |
gmtoffset | Optional. | Difference between GMT and local time in hours |
Format has the following available value.
Value | Description |
---|---|
SUNFUNCS_RET_STRING | returns the result as string. e.g. 15:46 (This is default) |
SUNFUNCS_RET_DOUBLE | returns the result as float. e.g. 12.123456 |
SUNFUNCS_RET_TIMESTAMP | returns the result as integer (timestamp). e.g. 1211233211) |
Return
PHP date_sunset() Function returns the time of the sunset, in the specified format, on success. FALSE on failure.
Example
Return the sunset time for Lisbon, Portugal today:
<?php/* j a v a 2 s .co m*/
echo("Lisbon, Portugal: Date: " . date("D M d Y"));
echo("<br>Sunset time: ");
echo(date_sunset(time(),SUNFUNCS_RET_STRING,18.1,-9,80,1));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP date_time_set() Function
- Syntax for PHP date_time_set() Function
- Parameter for PHP date_time_set() Function
- Return for PHP date_time_set() Function
- Example - Set the time
- Example - Procedural style
- Example - Values exceeding ranges are added to their parent values
Home » PHP Tutorial » PHP Date Functions