$val) {
echo "$format => $val" . PHP_EOL;
}
echo "Weekday: " . $dateArr["weekday"] . PHP_EOL;
echo "Weekday: " . getdate()["weekday"] . PHP_EOL;
echo "Weekday: " . getdate()["day"] . PHP_EOL;
echo "Year: " . getdate()["year"] . PHP_EOL;
echo "Minutes: " . getdate()["minutes"] . PHP_EOL;
echo "Hours: " . getdate()["hours"] . PHP_EOL;
echo "Month day: " . getdate()["mday"] . PHP_EOL;
?>
format('%Y years, %M months and %d days');
$present = new DateTime('now');
$future = new DateTime('last day of January 2024');
$interval = $present->diff($future);
// Output — 05 years, 04 months and 17 days
echo $interval->format('%Y years, %M months and %d days');
?>
add($the_interval);
// Output — It will be Saturday, 05 March, 2039 after 20 years, 05 months and 20 days from today.
echo 'It will be ' . $now->format('l, d F, Y') . ' after ' . $the_interval->format("%Y years, %M months and %d days") . ' from today.';
$now = date_create('now');
$the_interval = date_interval_create_from_date_string('20 years 05 months 20 days');
date_add($now, $the_interval);
// Output — It will be Saturday, 05 March, 2039 after 20 years, 05 months and 20 days from today.
echo 'It will be ' . $now->format('l, d F, Y') . ' after ' . $the_interval->format("%Y years, %M months and %d days") . ' from today.';
?>
$christmas) {
$christmas->add(new DateInterval('P1Y'));
}
if ($now < $christmas) {
$interval = $now->diff($christmas);
echo $interval->format('%a days') . ' until Christmas!';
}
if ($now == $christmas) {
echo 'Merry Christmas :)';
}
// Output — 103 days until Christmas!
?>