PHP | date_sunrise() Function
Last Updated :
03 Jul, 2018
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
// 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("\nsunrise 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
// 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("\nsunrise 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
Similar Reads
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. $t
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_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
PHP | DateTime sub() Function The DateTime::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTime object. Syntax: Object oriented style: DateTime DateTime::sub( DateInterval interval ) Procedural style: DateTime date_sub( DateTim
2 min read