phpdatetimetimestampleap-year

PHP: Adding years to a timestamp


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.


Solution

  • $newTimestamp = strtotime('+2 years', $timestamp);
    

    Replace "+2 years" as required.

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