PHP Date add 1 year

This example explains how one can add 1 year to existing date object. Example code in php to add 1 year to a date object.

 
 

Share on Google+Share on Google+

PHP Date add 1 year

Ads

This example explains how one can add 1 year to existing date object. Example code in php to add 1 year to a date object.

Adding 1 year to a php date object is sometimes useful to solve some programming problem. You can add 365 days to year, but the php provides method to add 1 year easily. The code given below will show how you can add 1 year in php program.

<?php

//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: 2009-08-29
Date After adding one year: Sunday 29th of August 2010

 

Advertisements

Posted on: August 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles