Tag Archives: Date

DateTime::add()

We can add number of of days, months, years, hours and seconds with a DateTime object.

Example

<?php
$date = new DateTime(‘2007-05-05’);
$date->add(new DateInterval(‘P5Y’));
echo $date->format(‘Y-m-d’) . “n”;
?>

Output

2012-05-05

date_add

Its an alias of DateTime::add()
We can add number of of days, months, years, hours and seconds with  a DateTime object.

Example

<?php

$date = new DateTime(“24-May-2011 20:15:22”);
echo $date->format(“d-m-Y H:i:s”).'<br />’;

date_add($date, new DateInterval(“P1Y”));
echo ‘<br />’.$date->format(“d-m-Y”).’ : I Year’;

?>

Output

24-05-2011 20:15:22

24-05-2012 : I Year

Date functions