(PHP 5 >= 5.1.2, PHP 7)

date_sun_infoDevuelve una matriz con información sobre la puesta/salida del sol y el comienzo/final del crepúsculo


array date_sun_info ( int $time , float $latitude , float $longitude )



Marca de tiempo.


Latitud en grados.


Longitud en grados.

Valores devueltos

Devuelve una matriz si se tuvo éxito o FALSE en caso de error.


Ejemplo #1 Un ejemplo de date_sun_info()

date_sun_info(strtotime("2006-12-12"), 31.766735.2333);
foreach (
$sun_info as $clave => $valor) {
"$clave: " date("H:i:s"$valor) . "\n";

El resultado del ejemplo sería:

sunrise: 05:52:11
sunset: 15:41:21
transit: 10:46:46
civil_twilight_begin: 05:24:08
civil_twilight_end: 16:09:24
nautical_twilight_begin: 04:52:25
nautical_twilight_end: 16:41:06
astronomical_twilight_begin: 04:21:32
astronomical_twilight_end: 17:12:00

Ver también

  • date_sunrise() - Devuelve la hora de la salida del sol de un día y ubicación dados
  • date_sunset() - Devuelve la hora de la puesta de sol de un día y ubicación dados

add a note add a note

User Contributed Notes 3 notes

7 years ago
I have been working on my own php script to get current down or up for sun and moon.   I had to add function for any places that have 24 hour sun. 

here is my code for places with 24 hour sun.

if ($sunrise == 0 && $sunset == 0) {
$sunrise24 = "";
$sunset24 = "";
//run suninfo
$sunup = date_sun_info(strtotime($year."-".$month."-".$day), $lat, $lon);

//check if sun is up all day.
if ($sunup[sunrise] == 1 && $sunup[sunrise] == 1) {
imagecopy($sky, $sun, 60, 20, 0, 0, $sun_width, $sun_height);
imagefill($sky, 0, 0, $bluesky);
nospam at nomail dot com
16 days ago
maybe I am wrong, but I think


SUNFUNCS_RET_STRING     Return local time
SUNFUNCS_RET_DOUBLE     Return local time
mother at localsnow dot com
7 years ago
We needed the length of the day, both sunrise to sunset and twilight to twilight for particular latitudes. Sun_info() is just the thing. We mistakenly thought 'transit' was this value, which it is not. Transit is the time of day the sun is at its zenith. To get length of day, one must perform math on the results of sun_info().

When doing math with time values, don't expect date() to do the conversion to hours:minutes:seconds. date() thinks the passed value is a time since the epoch. You will need to do your own conversion to hours:minutes:seconds, using something like the following:
function hms($val) {
// convert seconds to hours:minutes:seconds
$v-=($h*3600); // subtract hours
$v-=($m*60); // subtract minutes
$s=$v % 60; // seconds remaining
if ($h<10) {$h="0".$h;}
if (
$m<10) {$m="0".$m;}
if (
$s<10) {$s="0".$s;}

Regarding date_sunrise() and date_sunset(), these both return values without seconds and without correction for Daylight time. Whereas sun_info() handles seconds as well as Daylight time. It even handles dates prior to the epoch correctly as negative timestamps, at least as of php 5.2.12

For example,
sun_info(strtotime('July 4, 1776'),47.3506,-122.6417)
produces something like the following when using date_default_timezone_set('America/Los_Angeles') and
date("H:i:s", $val)

sunrise: 04:20:26 [-6106016374]
sunset: 20:09:03 [-6105959457]
transit: 12:14:45 [-6105987915]
civil_twilight_begin: 03:40:54 [-6106018746]
civil_twilight_end: 20:48:35 [-6105957085]
nautical_twilight_begin: 02:46:58 [-6106021982]
nautical_twilight_end: 21:42:31 [-6105953849]
astronomical_twilight_begin: 01:28:06 [-6106026714]
astronomical_twilight_end: 23:01:23 [-6105949117]

* * *
To Top