Wednesday, December 28, 2011

How one can add 1 year to existing date object


//Example to add 1 year to a date object
$currentDate = date("Y-m-d");// current date

//Display the current date
echo "Current Date: ".$currentDate."<br>";

//Add one year to current date
$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($currentDate)) . " +1 year");
echo "Date After adding one year: ".date('l dS \o\f F Y', $dateOneYearAdded)."<br>";

Output of the program:
Current Date: 2011-12-27
Date After adding one year: Friday 28th of December 2012

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth