date_sunrise() function in PHP


The date_sunrise() function returns the time of sunrise for a given day / location. It 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

  • timestamp − Timestamp of the day from which the sunrise time is taken.

  • format − Specifies how to return the result:

    • SUNFUNCS_RET_STRING : returns the result as string.

    • SUNFUNCS_RET_DOUBLE : returns the result as float.

    • SUNFUNCS_RET_TIMESTAMP :returns the result as integer (timestamp)

  • latitude − specifies the latitude of the location. The latitude defaults to North. If you want to specify a South value, you must pass a negative value.

  • longitude − specifies the longitude of the location. The longitude defaults to East. If you want to specify a West value, you must pass a negative value.

  • zenith − Defaults to date.sunrise_zenith

  • gmtoffset − The difference between GMT and local time in hours.

Return

The date_sunrise() function returns the time of the sunrise, in the specified format, on success. FALSE on failure.

Example

The following is an example −

 Live Demo

<?php
   echo("Date: " . date("D M d Y") . "<br />");
   echo("Sunrise time: ");
   echo(date_sunrise(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1));
?>

Output

The following is the output −

Date: Wed Oct 10 2018
Sunrise time: 07:43

Example

Let us see another example −

 Live Demo

<?php
   $res = strtotime('2018-10-25');
   var_dump(date_sunrise($res, SUNFUNCS_RET_STRING, 69.245833, -53.537222));
?>

Output

The following is the output −

string(5) "11:28"

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Dec-2019

38 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements