0

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.

user3864308
  • 25
  • 1
  • 9

2 Answers2

2

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')
Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

you can use:

$date = "2014-08-25";
$newdate = strtotime ( '+2 months' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-d' , $newdate );
derdida
  • 14,784
  • 16
  • 90
  • 139