PHP date add 5 year to current date

后端 未结 10 2038
野的像风
野的像风 2020-12-01 03:47

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:

相关标签:
10条回答
  • 2020-12-01 03:47

    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;
    
    0 讨论(0)
  • 2020-12-01 03:47

    try this:

    $yearnow= date("Y");
    $yearnext=$yearnow+1;
    echo date("Y")."-".$yearnext;
    
    0 讨论(0)
  • 2020-12-01 03:48

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

    0 讨论(0)
  • 2020-12-01 03:49

    Try with:

    $end = date('Y-m-d', strtotime('+5 years'));
    
    0 讨论(0)
  • 2020-12-01 03:52

    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 -

    0 讨论(0)
  • 2020-12-01 03:54

    Using Carbon:

    $dt = Carbon::now();
    echo $dt->addYears(5); 
    
    0 讨论(0)
提交回复
热议问题