PHPdate添加1年到当前date

我有这个PHP代码:

$end=date('Ym-d'); 

我用它来获取当前的date,我需要将来5年的date,例如:

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

我怎样才能做到这一点?

试试:

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

根据这个post 修改date
strtotime()是非常强大的,并允许你用相对expression式轻松修改/转换date:

程序

  $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 

约会时间

  $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 

你可以在strtotime()扔的东西是相当惊人的,非常人性化的可读性。 看看下个星期二这个例子。

程序

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

约会时间

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

请注意,上面的这些示例现在正在返回。 PHP支持的date和时间格式页面上列出了strtotime()和DateTime构造函数所需的时间格式的完整列表。

另一个例子,适合你的情况可能是: 基于这个职位

  <?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("jn Y")); echo date("F j Y", mktime(0,0,0, $thisMonth, $today+7, $thisYear)); //4 months from now: list($today,$thisMonth,$thisYear) = explode(" ", date("jn 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("jn Y")); echo date("F j Y", mktime(0,0,0, $thisMonth+2, $today+35, $thisYear+3)); ?> 

使用此代码可将几年或几个月或几天或几小时或几分钟或几秒添加到给定的date

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

您也可以减去replace+到 –

要添加一年到今天的date使用以下内容:

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

使用碳 :

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

尝试这个 ,

 $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; 

碳非常非常容易。 $date = "2016-02-16"; // Or Your date $newDate = Carbon::createFromFormat('Ym-d', $date)->addYear(1);

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

尝试这个:

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