Open In App

PHP | date_sunset() Function

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.

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 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 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:

Reference: http://php.net/manual/en/function.date-sunset.php


Article Tags :