[php] $date + 1 year?

I'm trying to get a date that is one year from the date I specify.

My code looks like this:

$futureDate=date('Y-m-d', strtotime('+one year', $startDate));

It's returning the wrong date. Any ideas why?

This question is related to php strtotime

The answer is


Try: $futureDate=date('Y-m-d',strtotime('+1 year',$startDate));


// Declare a variable for this year 
$this_year = date("Y");
// Add 1 to the variable
$next_year = $this_year + 1;
$year_after = $this_year + 2;

// Check your code
    echo "This year is ";
    echo $this_year;
    echo "<br />";
    echo "Next year is ";
    echo $next_year;
    echo "<br />";
    echo "The year after that is ";
    echo $year_after;

//1 year from today's date
echo date('d-m-Y', strtotime('+1 year'));

//1 year from from specific date
echo date('22-09-Y', strtotime('+1 year'));

hope this simpler bit of code helps someone in future :)


strtotime() is returning bool(false), because it can't parse the string '+one year' (it doesn't understand "one"). false is then being implicitly cast to the integer timestamp 0. It's a good idea to verify strtotime()'s output isn't bool(false) before you go shoving it in other functions.

From the docs:

Return Values

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.


In my case (i want to add 3 years to current date) the solution was:

$future_date = date('Y-m-d', strtotime("now + 3 years"));

To Gardenee, Treby and Daniel Lima: what will happen with 29th February? Sometimes February has only 28 days :)


Try This

$nextyear  = date("M d,Y",mktime(0, 0, 0, date("m",strtotime($startDate)),   date("d",strtotime($startDate)),   date("Y",strtotime($startDate))+1));

just had the same problem, however this was the simplest solution:

<?php (date('Y')+1).date('-m-d'); ?>

There is also a simpler and less sophisticated solution:

$monthDay = date('m/d');
$year = date('Y')+1;
$oneYearFuture = "".$monthDay."/".$year."";
echo"The date one year in the future is: ".$oneYearFuture."";

$futureDate=date('Y-m-d', strtotime('+1 year'));

$futureDate is one year from now!

$futureDate=date('Y-m-d', strtotime('+1 year', strtotime($startDate)) );

$futureDate is one year from $startDate!


If you are using PHP 5.3, it is because you need to set the default time zone:

date_default_timezone_set()

I prefer the OO approach:

$date = new \DateTimeImmutable('today'); //'today' gives midnight, leave blank for current time.
$futureDate = $date->add(\DateInterval::createFromDateString('+1 Year'))

Use DateTimeImmutable otherwise you will modify the original date too! more on DateTimeImmutable: http://php.net/manual/en/class.datetimeimmutable.php


If you just want from todays date then you can always do:

new \DateTimeImmutable('-1 Month');

My solution is: date('Y-m-d', time()-60*60*24*365);

You can make it more "readable" with defines:

define('ONE_SECOND', 1);
define('ONE_MINUTE', 60 * ONE_SECOND);
define('ONE_HOUR',   60 * ONE_MINUTE);
define('ONE_DAY',    24 * ONE_HOUR);
define('ONE_YEAR',  365 * ONE_DAY);

date('Y-m-d', time()-ONE_YEAR);