Home Tutorial Php Phpdate PHP Date add 1 year

 
 

PHP Date add 1 year
Posted on: August 29, 2009 at 12:00 AM
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

 

Related Tags for PHP Date add 1 year:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.