添加时间到日期php [复制]

添加时间到日期php [复制]

问题描述:

This question already has an answer here:

here is my current issue: I need to add a predefined amount to a selected date. I have been using this until now:

$date=date('Y-m-d', strtotime('+7 days'));

but this returns the current date +7 days.

How can I define the current date and the modify that using this? lets say that I have the date defined as:

$udate='2014-05-06';

I need to add 2 months to this date.

</div>

此问题已经存在 这里有一个答案: p>

  • 添加日期的天数 19 answers span> li> ul> div>

    这是我当前的问题: 我需要在预定日期添加预定义金额。 我一直在使用它: p>

      $ date = date('Ym-d',strtotime('+ 7 days')); 
      code>  
     
     

    但这会返回当前日期+7天。 p>

    如何定义当前日期和使用此日期的修改? lets说我 将日期定义为: p>

      $ udate ='2014-05-06'; 
      code>  pre> 
     
     

    我需要 添加2个月到此日期。 p> div>

You can do,

date('Y-m-d',strtotime(date("Y-m-d", strtotime($your_date)) . " +2 months"));

You can also do using DateTime object,

$date = new DateTime($your_date);
$interval = new DateInterval('P2M');    
$date->add($interval);
echo $date->format('Y-m-d')

you can use:

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