Tutorialspoint.dev

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, $gmtoffset )

Parameters: The date_sunrise() function accepts four parameters as mentioned above and described below:

  • $timestamp: It is a mandatory parameter which specifies the timestamp of the day from which the sunrise time is taken.
  • $format: It is an optional parameter which specifies format to return the result.
    • SUNFUNCS_RET_STRING: Returns a string. e.g. 16:46 (by default)
    • SUNFUNCS_RET_DOUBLE: Returns a float. e.g. 16.78243132
    • SUNFUNCS_RET_TIMESTAMP: Returns the result as integer (timestamp) e.g. 1095034606.
  • $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 defaults 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.sunrise_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 sunrise, 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_sunrise() function.

Program 1:

<?php
// PHP program to show sunrise 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(" sunrise time: ");
echo(date_sunrise(time(), SUNFUNCS_RET_STRING,
                  28.6139, 77.2090, 90, 5.30));
?>

Output:

Tue Jun 26 2018
sunrise time: 05:16

Program 2:

<?php
// PHP program to show sunrise 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(" sunrise time: ");
echo(date_sunrise(time(), SUNFUNCS_RET_STRING,
              28.501120, 77.409989, 90, 5.30));
?>

Output:

Tue Jun 26 2018
sunrise time: 05:15

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



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter