Php 为日期添加时间

Php 为日期添加时间,php,date,add,Php,Date,Add,以下是我的最新一期: 我需要向选定日期添加预定义金额。我一直在使用这个: $date=date('Y-m-d', strtotime('+7 days')); 但这将返回当前日期+7天 我如何定义当前日期以及使用该日期修改的日期? 假设我将日期定义为: $udate='2014-05-06'; 我需要在这个日期上再加两个月。你可以这样做 date('Y-m-d',strtotime(date("Y-m-d", strtotime($your_date)) . " +2 months"));

以下是我的最新一期: 我需要向选定日期添加预定义金额。我一直在使用这个:

$date=date('Y-m-d', strtotime('+7 days'));
但这将返回当前日期+7天

我如何定义当前日期以及使用该日期修改的日期? 假设我将日期定义为:

$udate='2014-05-06';
我需要在这个日期上再加两个月。

你可以这样做

date('Y-m-d',strtotime(date("Y-m-d", strtotime($your_date)) . " +2 months"));
您也可以使用对象

您可以使用:

$date = "2014-08-25";
$newdate = strtotime ( '+2 months' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-d' , $newdate );

查看我的答案和检查当然,快速查看手册可能会给您一个答案,在发布问题之前,我为此浪费了半天时间。+1用于使用
DateTime
类或使用
->modify(“+2个月”)
DateTime
对象上,该对象也适用于php>=5.2.0。它也是更“可读”的代码:)
$date = "2014-08-25";
$newdate = strtotime ( '+2 months' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-d' , $newdate );