English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The date_sunrise() function accepts a timestamp representing a given date and returns the sunrise time for that specific date.
date_sunrise()The function accepts a timestamp representing a given day and returns the sunrise time for that specific day.
date_sunrise($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; i.e., SUNFUNCS_RET_STRING(string),SUNFUNCS_RET_DOUBLE(Floating point number) and SUNFUNCS_RET_TIMESTAMP 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 needs to 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 needs to 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 PHP date_sunrise() function returns the sunrise time in the required format. If it fails, it will return a boolean valuefalse.
This function was originally introduced in PHP 5introduced in version 5.2.0 and can be used in all higher versions.
The following example demonstratesdate_sunrise()Function usage-
<?php $sun_info = date_sunrise("02-17-2012"); print_r($sun_info); ?>Test and see‹/›
Output result
04:39
Now, call this function by passing 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_sunrise("02-03-202 23.4, -25 print_r("Sunrise Time: ").$sun_info, ?>Test and see‹/›
Output result
Sunrise Time: 08:21
The following example verifies the case with no sunrise-
<?php $sun_info = date_sunrise("25-12-2016", SUNFUNCS_RET_STRING, 69, 41 print("Sunrise Time: ").$sun_info, print("\n"); var_dump($sun_info); ?>Test and see‹/›
Output result
Sunrise Time: bool(false)
<?php echo("Date: ".date("D M d Y")); echo("\n"); echo("Sunrise time: "); echo(date_sunrise(time(), SUNFUNCS_RET_STRING,38.4,-9,90,1)); ?>Test and see‹/›
Output result
Date: Thu May 07 2020 Sunrise time: 06:34