Search code examples
phpdatestrtotime

Adding three months to a date in PHP


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.


Solution

  • Change it to this will give you the expected format:

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