Adding three months to a date in PHP

user979331 picture user979331 · Mar 26, 2012 · Viewed 186.5k times · Source

I have a variable called $effectiveDate containing the date 2012-03-26.

I am trying to add three months to this date and have been unsuccessful at it.

Here is what I have tried:

$effectiveDate = strtotime("+3 months", strtotime($effectiveDate));

and

$effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months");

What am I doing wrong? Neither piece of code worked.

Answer

Tchoupi picture Tchoupi · Mar 26, 2012

Change it to this will give you the expected format:

$effectiveDate = date('Y-m-d', strtotime("+3 months", strtotime($effectiveDate)));