PHP: Adding years to a timestamp

Onema picture Onema · Mar 2, 2011 · Viewed 35.2k times · Source

In PHP given a UTC timestamp I would like to add exactly N number of years. This should take into consideration leap years.

Thank you.

Answer

Jeff Parker picture Jeff Parker · Mar 2, 2011
$newTimestamp = strtotime('+2 years', $timestamp);

Replace "+2 years" as required.

ref: http://php.net/manual/en/function.strtotime.php