Shows Call to a member function format() on boolean error in php after editing
<p>Here is the original script</p>

<pre><code>&lt;?php

$monthToAdd = 36;

$d1 = DateTime::createFromFormat('Y-m-d', '2016-04-10');

$year = $d1-&gt;format('Y');
$month = $d1-&gt;format('n');
$day = $d1-&gt;format('d');

$year += floor($monthToAdd/12);
$monthToAdd = $monthToAdd%12;
$month += $monthToAdd;
if($month &gt; 12) {
    $year ++;
    $month = $month % 12;
    if($month === 0)
        $month = 12;
}

if(!checkdate($month, $day, $year)) {
    $d2 = DateTime::createFromFormat('Y-n-j', $year.'-'.$month.'-1');
    $d2-&gt;modify('last day of');
}else {
    $d2 = DateTime::createFromFormat('Y-n-d', $year.'-'.$month.'-'.$day);
}
$d2-&gt;setTime($d1-&gt;format('H'), $d1-&gt;format('i'), $d1-&gt;format('s'));

echo $d2-&gt;format('d-m-Y');

?&gt;
</code></pre>

<p>and here is the one that I edited</p>

<pre><code>&lt;?php

$y = 2016;
$m = 04;
$d = 10;
$monthToAdd = 36;

$d1 = DateTime::createFromFormat('Y-m-d', '$y-$m-$d');

$year = $d1-&gt;format('Y');
$month = $d1-&gt;format('n');
$day = $d1-&gt;format('d');

$year += floor($monthToAdd/12);
$monthToAdd = $monthToAdd%12;
$month += $monthToAdd;
if($month &gt; 12) {
    $year ++;
    $month = $month % 12;
    if($month === 0)
        $month = 12;
}

if(!checkdate($month, $day, $year)) {
    $d2 = DateTime::createFromFormat('Y-n-j', $year.'-'.$month.'-1');
    $d2-&gt;modify('last day of');
}else {
    $d2 = DateTime::createFromFormat('Y-n-d', $year.'-'.$month.'-'.$day);
}
$d2-&gt;setTime($d1-&gt;format('H'), $d1-&gt;format('i'), $d1-&gt;format('s'));

echo $d2-&gt;format('d-m-Y');

?&gt;
</code></pre>

<p>it give error</p>

<p>Idea is to add X value as month , show the result.
For example the date provided is "2016-04-10" and $monthToAdd = 4; , it should give a result of 2016-08-10</p>

<p>script was working , but I just want to add a form so that user can input month to calculate.
I am new to php, anyone help ?</p>