Tag Archives: Date

date_sunset

It returns time of sunset for a given day and location

Example

<?php
echo date(“D M d Y”). ‘, sunset time : ‘ .date_sunset(time(), SUNFUNCS_RET_STRING, 18.4, -19, 80, 2);
?>

Output

Wed Apr 25 2012, sunset time : 20:50

date_sunrise

It returns time of sunrise for a given day and location
Example

<?php
echo date(“D M d Y”). ‘, sunrise time : ‘ .date_sunrise(time(), SUNFUNCS_RET_STRING, 18.4, -19, 80, 2);
?>

Output

Tue Apr 24 2012, sunrise time : 09:38

date_sun_info

It Returns an array with information about sunset/sunrise and twilight begin/end

Example

<?php
$sunInfo = date_sun_info(strtotime(“2006-05-17”), 11.7667, 15.2333);
foreach ($sunInfo as $key => $val) {
echo “$key: ” . date(“H:i:s”, $val) . “<br />”;
}
?>

Output

sunrise: 10:04:55
sunset: 22:45:58
transit: 16:25:27
civil_twilight_begin: 09:42:25
civil_twilight_end: 23:08:28
nautical_twilight_begin: 09:15:57
nautical_twilight_end: 23:34:56
astronomical_twilight_begin: 08:49:06
astronomical_twilight_end: 00:01:47

DateTime::sub

It subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
Example

<?php
$date = new DateTime(‘2012-05-17’);
$date->sub(new DateInterval(‘P11D’));
echo $date->format(‘Y-m-d’) . “n”;
?>

Output

2012-05-06

date_sub

Its an alias of DateTime::sub()and subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
Example

<?php
$date = date_create(‘2012-05-17′);
date_sub($date, date_interval_create_from_date_string(’11 days’));
echo date_format($date, ‘Y-m-d’);
?>

Output

2012-05-06


date_parse

It returns associative array with detailed info about given date

Example

<?php
echo “<pre>”;
print_r(date_parse(“2006-12-12 10:00:00.5”));
?>

Output

Array
(
[year] => 2006
[month] => 12
[day] => 12
[hour] => 10
[minute] => 0
[second] => 0
[fraction] => 0.5
[warning_count] => 0
[warnings] => Array
(
)

[error_count] => 0
[errors] => Array
(
)

[is_localtime] =>
)

date_parse_from_format

It returns details  about given date formatted according to the specified format.

Example

<?php
echo “<pre>”;
$date = “20.4.2008”;
print_r(date_parse_from_format(“j.n.Y H:iP”, $date));
?>

Output

Array
(
[year] => 2008
[month] => 4
[day] => 20
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)

[error_count] => 1
[errors] => Array
(
[9] => Data missing
)

[is_localtime] =>
)