PHP | date_sunset() Function Last Updated : 03 Jul, 2018 Comments Improve Suggest changes Like Article Like Report The date_sunset() is an inbuilt function in PHP which is used to find the sunset time for a specified day and location. Syntax: date_sunset ( $timestamp, $format, $latitude, $longitude, $zenith, $gmtoffset ) Parameters: This function accepts four parameters as mentioned above and described below. $timestamp: It is a required parameter which specifies the timestamp of the day from which the sunset time is taken. $format: It is an optional parameter which specifies the format to return the result. Return format are given below: SUNFUNCS_RET_STRING: Returns a string. e.g. 16:46 (by default) SUNFUNCS_RET_DOUBLE: Returns a float. e.g. 16.12345 SUNFUNCS_RET_TIMESTAMP: Returns the result as integer (timestamp). e.g. 987123569 $latitude: It is an optional parameter which specifies the latitude of the location. By default, it set as North. To specify a value for South, pass in a negative value. $longitude: It is an optional parameter which specifies the longitude of the location. By default, it set as East. To modify a value for West, pass in a negative value. $zenith: It is an Optional parameter. The zenith is the angle between the center of the sun and a line perpendicular to earth's surface, by default it is date.sunset_zenith. $gmtoffset: It is optional parameter and used to specifies the difference between GMT and local time in hours. Return Value: It returns the time of the sunset, in the specified format, on success. FALSE on failure. Exceptions: This function generates E_NOTICE error if date/time function is invalid and E_STRICT or E_WARNING if using the system setting or the TZ environment variable. Below programs illustrate the date_sunset() function in PHP. Program 1: php <?php // PHP program to show sunset time // of New delhi india for current day // Longitude and latitude of Delhi India // 28.6139° N, 77.2090° E // GMT(Greenwich Mean Time) +5.30 // Zenith ~= 90 echo date("D M d Y"); echo("\nSunset time: "); echo(date_sunset(time(), SUNFUNCS_RET_STRING, 28.6139, 77.2090, 90, 5.30)); ?> Output: Wed Jun 27 2018 Sunset time: 19:07 Program 2: php <?php // PHP program to show sunset time // of GFG Noida for a Current day // Longitude and latitude of GeeksforGeeks // Noida 28°30'04.0"N 77°24'36.0"E // GMT(Greenwich Mean Time) +5.30 // Zenith ~= 90 echo date("D M d Y"); echo("\nSunset time: "); echo(date_sunset(time(), SUNFUNCS_RET_STRING, 28.501120, 77.409989, 90, 5.30)); ?> Output: Wed Jun 27 2018 Sunset time: 19:06 Related Articles: PHP | date_sunrise() Function PHP | date_modify() Function Reference: http://php.net/manual/en/function.date-sunset.php Comment More infoAdvertise with us Next Article PHP | date_sunset() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | date_sunrise() Function The date_sunrise() is an inbuilt function in PHP which is used to find the sunrise time for a specified day and location. This function returns the time of the sunrise, in the specified format, on success. FALSE on failure. Syntax: date_sunrise ( $timestamp, $format, $latitude, $longitude, $zenith, 2 min read PHP date_sub() Function The date_sub() function is an inbuilt function in PHP that is used to subtract days, months, years, hours, minutes, and seconds from given date. This function returns a DateTime object on success and FALSE on failure. Syntax: date_sub($object, $interval)Parameters: The date_sub() function accepts tw 2 min read PHP | date_sun_info() Function The date_sun_info() is an inbuilt function in PHP which is used to find the information about sunset/sunrise and twilight begin/end for a specified day and location.Syntax: array date_sun_info($timestamp, $latitude, $longitude) Parameters: This function accepts three parameters as mentioned above an 2 min read PHP | date_date_set() Function The date_date_set() function is an inbuilt function in PHP which is used to set a new Date. This function has four parameters $object, $year, $month and $day and returns DateTime object on success or false on failure. The date_date_set() function is an alias of DateTime::setDate() function. Syntax: 2 min read PHP | date_time_set() Function The date_time_set() function is an inbuilt function in PHP which is used to sets the time. This function resets the current time of the DateTime object to a different time. Syntax: Procedural style: date_time_set( $object, $hour, $minute, $second, $microseconds ) Object oriented style: DateTime::set 2 min read Like