PHP date add 5 year to current date

Php

Php Problem Overview


I have this PHP code:

$end=date('Y-m-d');

I use it to get the current date, and I need the date 5 years in the future, something like:

$end=date('(Y + 5)-m-d');

How can I do this?

Php Solutions


Solution 1 - Php

Try with:

$end = date('Y-m-d', strtotime('+5 years'));

Solution 2 - Php

Modifying dates based on this post
strtotime() is really powerful and allows you to modify/transform dates easily with it’s relative expressions too:

Procedural

    $dateString = '2011-05-01 09:22:34';
    $t = strtotime($dateString);
    $t2 = strtotime('-3 days', $t);
    echo date('r', $t2) . PHP_EOL; // returns: Thu, 28 Apr 2011 09:22:34 +0100

DateTime

    $dateString = '2011-05-01 09:22:34';
    $dt = new DateTime($dateString);
    $dt->modify('-3 days');
    echo $dt->format('r') . PHP_EOL; // returns: Thu, 28 Apr 2011 09:22:34 +0100

The stuff you can throw at strtotime() is quite surprising and very human readable. Have a look at this example looking for Tuesday next week.

Procedural

    $t = strtotime("Tuesday next week");
    echo date('r', $t) . PHP_EOL; // returns: Tue, 10 May 2011 00:00:00 +0100

DateTime

    $dt = new DateTime("Tuesday next week");
    echo $dt->format('r') . PHP_EOL; // returns: Tue, 10 May 2011 00:00:00 +0100

Note that these examples above are being returned relative to the time now. The full list of time formats that strtotime() and the DateTime constructor takes are listed on the PHP Supported Date and Time Formats page.

Another example, suitable for your case could be: based on this post

    <?php
    //How to get the day 3 days from now:
    $today = date("j");
    $thisMonth = date("n");
    $thisYear = date("Y");
    echo date("F j Y", mktime(0,0,0, $thisMonth, $today+3, $thisYear)); 
      
    //1 week from now:
    list($today,$thisMonth,$thisYear) = explode(" ", date("j n Y"));
    echo date("F j Y", mktime(0,0,0, $thisMonth, $today+7, $thisYear));
      
    //4 months from now:
    list($today,$thisMonth,$thisYear) = explode(" ", date("j n Y"));
    echo date("F j Y", mktime(0,0,0, $thisMonth+4, $today, $thisYear)); 
      
    //3 years, 2 months and 35 days from now:
    list($today,$thisMonth,$thisYear) = explode(" ", date("j n Y"));
    echo date("F j Y", mktime(0,0,0, $thisMonth+2, $today+35, $thisYear+3));
    ?>

Solution 3 - Php

Use this code to add years or months or days or hours or minutes or seconds to a given date

 echo date("Y-m-d H:i:s", strtotime("+1 years", strtotime('2014-05-22 10:35:10'))); //2015-05-22 10:35:10
 echo date("Y-m-d H:i:s", strtotime("+1 months", strtotime('2014-05-22 10:35:10')));//2014-06-22 10:35:10
 echo date("Y-m-d H:i:s", strtotime("+1 days", strtotime('2014-05-22 10:35:10')));//2014-05-23 10:35:10
 echo date("Y-m-d H:i:s", strtotime("+1 hours", strtotime('2014-05-22 10:35:10')));//2014-05-22 11:35:10
 echo date("Y-m-d H:i:s", strtotime("+1 minutes", strtotime('2014-05-22 10:35:10')));//2014-05-22 10:36:10
 echo date("Y-m-d H:i:s", strtotime("+1 seconds", strtotime('2014-05-22 10:35:10')));//2014-05-22 10:35:11

You can also subtract replacing + to -

Solution 4 - Php

       $date = strtotime($row['timestamp']);
	   $newdate = date('d-m-Y',strtotime("+1 year",$date));

Solution 5 - Php

Its very very easy with Carbon.

$date = "2016-02-16"; // Or Your date
$newDate    = Carbon::createFromFormat('Y-m-d', $date)->addYear(1);

Solution 6 - Php

Using Carbon:

$dt = Carbon::now();
echo $dt->addYears(5); 

Solution 7 - Php

To add one year to todays date use the following:

$oneYearOn = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " + 365 day"));

Solution 8 - Php

You may use DateInterval for this purpose;

$currentDate = new \DateTime(); //creates today timestamp
$currentDate->add(new \DateInterval('P5Y')); //this means 5 Years
and you can now format it;
$currentDate->format('Y-m-d');

Solution 9 - Php

Try below code, i hope it will be helpful for you

<?php

$current_date=strtotime(date('Y-m-d'));

echo $end = date('Y-m-d', strtotime('+5 years',$current_date));

?>

Solution 10 - Php

try this ,

$presentyear = '2013-08-16 12:00:00';

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

echo $nextyear;

Solution 11 - Php

try this:

$yearnow= date("Y");
$yearnext=$yearnow+1;
echo date("Y")."-".$yearnext;

Solution 12 - Php

Try this code and add next Days, Months and Years

// current month: Aug 2018
$n = 2;
for ($i = 0; $i <= $n; $i++){
   $d = strtotime("$i days");
   $x = strtotime("$i month");
   $y = strtotime("$i year");
   echo "Dates : ".$dates = date('d M Y', "+$d days");
   echo "<br>";
   echo "Months : ".$months = date('M Y', "+$x months");
   echo '<br>';
   echo "Years : ".$years = date('Y', "+$y years");
   echo '<br>';
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLetterView Question on Stackoverflow
Solution 1 - PhphszView Answer on Stackoverflow
Solution 2 - PhpGadomaView Answer on Stackoverflow
Solution 3 - PhpRN KushwahaView Answer on Stackoverflow
Solution 4 - PhpNiravView Answer on Stackoverflow
Solution 5 - PhpBijaya Prasad KuikelView Answer on Stackoverflow
Solution 6 - PhpciruvanView Answer on Stackoverflow
Solution 7 - PhpDeepuView Answer on Stackoverflow
Solution 8 - PhpTuncay ElvanağaçView Answer on Stackoverflow
Solution 9 - PhpDivyeshView Answer on Stackoverflow
Solution 10 - PhpAbhiView Answer on Stackoverflow
Solution 11 - PhpGoldTechnia Pvt. Ltd.View Answer on Stackoverflow
Solution 12 - PhpRahul GandhiView Answer on Stackoverflow