Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 999
Onema Avatar asked Mar 02 '11 20:03

Onema


People also ask

What does Strtotime mean in PHP?

Definition and Usage The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

What does Strtotime return?

Return Values PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.

What is timestamp format in PHP?

Summary. The date function in PHP is used to format the timestamp into a human desired format. The timestamp is the number of seconds between the current time and 1st January, 1970 00:00:00 GMT. It is also known as the UNIX timestamp.


1 Answers

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

Replace "+2 years" as required.

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

like image 183
Jeff Parker Avatar answered Sep 20 '22 10:09

Jeff Parker