English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The date_sunset() function returns the sunset time for the given date/The sunset time of the location.
date_sunset()The function accepts a timestamp representing a given day and returns the sunset time for that specific date.
date_sunset($timestamp, [$format, $latitude, $longitude, $zenith, $gmtoffset])
Serial Number | Parameters and Description |
---|---|
1 | timestamp (required) This specifies a timestamp. |
2 | format (optional) This specifies the format you need to use for the result value. You can pass three constants as the value of this parameter; That is: SUNFUNCS_RET_STRING(,, Integer. |
3 | latitude (optional) By default, this option specifies the latitude of a location, which specifies the north direction. To specify the latitude value of the south, it must be passed as a negative value. |
4 | longitude (optional) By default, it specifies the longitude of a location, which specifies the east direction. To specify the longitude value of the west, it must be passed as a negative value. |
5 | zenith (optional) This specifies the zenith value. This specifies the angle between the line perpendicular to the Earth's surface and the center of the sun. |
6 | gmtoffset (optional) This specifies the time difference between GMT and local time (in hours). |
The date_sunset() function returns the sunset time in the required format. If it fails, it will return a boolean valuefalse.
This function was originally introduced in PHP 5.0 version introduced and can be used in all higher versions.
The following example demonstratesdate_sunset()Function usage-
<?php $sun_info = date_sunset("02-17-2012"); print_r($sun_info); ?>Test and see‹/›
Output result
14:46
Now, to call this function, you must pass the latitude and longitude values. If you want to pass latitude and longitude values, you must also pass the required format values-
<?php $sun_info = date_sunset("02-03-2020", SUNFUNCS_RET_STRING, 23.4, -25); print_r("Sunset Time: ".$sun_info); ?>Test and see‹/›
Output result
Sunset Time: 19:05
The following example verifies the case without sunset-
<?php $sun_info = date_sunset("25-12-2016", SUNFUNCS_RET_STRING, 69, 41); print("Sunset Time: ".$sun_info); print("\n"); var_dump($sun_info); ?>Test and see‹/›
Output result
Sunset Time: bool(false)
<?php echo("Date: ".date("D M d Y")); echo("\n"); echo("Sunset time: "); echo(date_sunset(time(), SUNFUNCS_RET_STRING,38.4,-9,90,1)); ?>Test and see‹/›
Output result
Date: Thu May 07 2020 Sunset time: 20:30