<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns time of sunrise for a given day and location</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-sun-info.html">date_sun_info</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-sunset.html">date_sunset</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.date-sunrise" class="refentry"> <div class="refnamediv"> <h1 class="refname">date_sunrise</h1> <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">date_sunrise</span> — <span class="dc-title">Returns time of sunrise for a given day and location</span></p> </div> <div class="refsect1 description" id="refsect1-function.date-sunrise-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>date_sunrise</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code><span class="initializer"> = SUNFUNCS_RET_STRING</span></span> [, <span class="methodparam"><span class="type">float</span> <code class="parameter">$latitude</code><span class="initializer"> = ini_get("date.default_latitude")</span></span> [, <span class="methodparam"><span class="type">float</span> <code class="parameter">$longitude</code><span class="initializer"> = ini_get("date.default_longitude")</span></span> [, <span class="methodparam"><span class="type">float</span> <code class="parameter">$zenith</code><span class="initializer"> = ini_get("date.sunrise_zenith")</span></span> [, <span class="methodparam"><span class="type">float</span> <code class="parameter">$gmt_offset</code><span class="initializer"> = 0</span></span> ]]]]] )</div> <p class="para rdfs-comment"> <span class="function"><strong>date_sunrise()</strong></span> returns the sunrise time for a given day (specified as a <code class="parameter">timestamp</code>) and location. </p> </div> <div class="refsect1 parameters" id="refsect1-function.date-sunrise-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">timestamp</code></dt> <dd> <p class="para"> The <code class="parameter">timestamp</code> of the day from which the sunrise time is taken. </p> </dd> <dt> <code class="parameter">format</code></dt> <dd> <p class="para"> <table class="doctable table"> <caption><strong><code class="parameter">format</code> constants</strong></caption> <thead> <tr> <th>constant</th> <th>description</th> <th>example</th> </tr> </thead> <tbody class="tbody"> <tr> <td>SUNFUNCS_RET_STRING</td> <td>returns the result as <span class="type"><a href="language.types.string.html" class="type string">string</a></span></td> <td>16:46</td> </tr> <tr> <td>SUNFUNCS_RET_DOUBLE</td> <td>returns the result as <span class="type"><a href="language.types.float.html" class="type float">float</a></span></td> <td>16.78243132</td> </tr> <tr> <td>SUNFUNCS_RET_TIMESTAMP</td> <td>returns the result as <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> (timestamp)</td> <td>1095034606</td> </tr> </tbody> </table> </p> </dd> <dt> <code class="parameter">latitude</code></dt> <dd> <p class="para"> Defaults to North, pass in a negative value for South. See also: <a href="datetime.configuration.html#ini.date.default-latitude" class="link">date.default_latitude</a> </p> </dd> <dt> <code class="parameter">longitude</code></dt> <dd> <p class="para"> Defaults to East, pass in a negative value for West. See also: <a href="datetime.configuration.html#ini.date.default-longitude" class="link">date.default_longitude</a> </p> </dd> <dt> <code class="parameter">zenith</code></dt> <dd> <p class="para"> <code class="parameter">zenith</code> is the angle between the center of the sun and a line perpendicular to earth's surface. It defaults to <a href="datetime.configuration.html#ini.date.sunrise-zenith" class="link">date.sunrise_zenith</a> <table class="doctable table"> <caption><strong>Common <code class="parameter">zenith</code> angles</strong></caption> <thead> <tr> <th>Angle</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>90°50'</td> <td>Sunrise: the point where the sun becomes visible.</td> </tr> <tr> <td>96°</td> <td>Civil twilight: conventionally used to signify the start of dawn.</td> </tr> <tr> <td>102°</td> <td>Nautical twilight: the point at which the horizon starts being visible at sea.</td> </tr> <tr> <td>108°</td> <td>Astronomical twilight: the point at which the sun starts being the source of any illumination.</td> </tr> </tbody> </table> </p> </dd> <dt> <code class="parameter">gmtoffset</code></dt> <dd> <p class="para"> Specified in hours. The <code class="parameter">gmtoffset</code> is ignored, if <code class="parameter">format</code> is <strong><code>SUNFUNCS_RET_TIMESTAMP</code></strong>. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.date-sunrise-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the sunrise time in a specified <code class="parameter">format</code> on success or <strong><code>FALSE</code></strong> on failure. One potential reason for failure is that the sun does not rise at all, which happens inside the polar circles for part of the year. </p> </div> <div class="refsect1 errors" id="refsect1-function.date-sunrise-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Every call to a date/time function will generate a <strong><code>E_NOTICE</code></strong> if the time zone is not valid, and/or a <strong><code>E_STRICT</code></strong> or <strong><code>E_WARNING</code></strong> message if using the system settings or the <var class="varname"><var class="varname">TZ</var></var> environment variable. See also <span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span></p> </div> <div class="refsect1 changelog" id="refsect1-function.date-sunrise-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr><td>5.1.0</td><td><p class="para"> Now issues the <strong><code>E_STRICT</code></strong> and <strong><code>E_NOTICE</code></strong> time zone errors.</p></td></tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.date-sunrise-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2797"> <p><strong>Example #1 <span class="function"><strong>date_sunrise()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/* calculate the sunrise time for Lisbon, Portugal<br />Latitude: 38.4 North<br />Longitude: 9 West<br />Zenith ~= 90<br />offset: +1 GMT<br />*/<br /><br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D M d Y"</span><span style="color: #007700">). </span><span style="color: #DD0000">', sunrise time : ' </span><span style="color: #007700">.</span><span style="color: #0000BB">date_sunrise</span><span style="color: #007700">(</span><span style="color: #0000BB">time</span><span style="color: #007700">(), </span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">, </span><span style="color: #0000BB">38.4</span><span style="color: #007700">, -</span><span style="color: #0000BB">9</span><span style="color: #007700">, </span><span style="color: #0000BB">90</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Mon Dec 20 2004, sunrise time : 08:54 </pre></div> </div> </div> <div class="example" id="example-2798"> <p><strong>Example #2 No sunrise</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$solstice </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2017-12-21'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_sunrise</span><span style="color: #007700">(</span><span style="color: #0000BB">$solstice</span><span style="color: #007700">, </span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">, </span><span style="color: #0000BB">69.245833</span><span style="color: #007700">, -</span><span style="color: #0000BB">53.537222</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> bool(false) </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.date-sunrise-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.date-sunset.html" class="function" rel="rdfs-seeAlso">date_sunset()</a> - Returns time of sunset for a given day and location</span></li> <li class="member"><span class="function"><a href="function.date-sun-info.html" class="function" rel="rdfs-seeAlso">date_sun_info()</a> - Returns an array with information about sunset/sunrise and twilight begin/end</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-sun-info.html">date_sun_info</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-sunset.html">date_sunset</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>