PHP datesunrise

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : date_sunrise() function

Description

The date_sunrise() function is used to get the time of sunrise for a given day and location.

Version

(PHP 4 and above)

Syntax

date_sunrise(timestamp, format, latitude, longitude, zenith, gmt_offset)

Parameters

Name

Description

Required /
Optional

OptionalType

timestamp

The timestamp of the day.

Required

Integer

format

Sets the format of the output. 

Use SUNFUNCS_RET_STRING if you want the output as string (example 16:46) 

Use UNFUNCS_RET_DOUBLE if you want the output as float (example 16.78243132) 

Use SUNFUNCS_RET_TIMESTAMP if you want the output as integer (example 1095034606)

Optional

Float

latitude

Indicates the latitude of a location Use a negative value for South. Default is North.

Optional

Float

longitude

Indicates the longitude of a location. Use a negative value for West. Default is East.

Optional

Float

zenith

Solar zenith angle.

Optional

Float

gmt_offset

Difference between GMT and local time in hours. For example, since the difference between GMT and Calcutta-India is five and half hours, therefore for IST, use 5.50.

Optional

Float

 

Return value

The sunrise time in a specified format on success, or FALSE on failure.

Value Type : Mixed*

*Mixed : Mixed indicates multiple (but not necessarily all) types.

Example :

  1. //Calculate the sunrise time for Kolkata, India  

  2. //Latitude: 22.34 North  

  3. //Longitude: 88.24 East  

  4. //Zenith ~= 45.6177°  

  5. //offset: +5.50 GMT  

  6. echo("Date: " . date("D M d Y") . "
    ");  

  7. echo("Sunrise time: ");  

  8. echo(date_sunrise(time(),SUNFUNCS_RET_STRING,22.34,88.24,90.5546,5.50));  

  9. ?>  

Output :

Date: Tue Jan 18 2011

Sunrise time: 06:18

Note : Since sunrise time depends on particular day and location, therefore, the output may vary shown under Output of the example in this tutorial.