MySQL's DATE_ADD function in PHP
<p>I need to implement the MySQL DATE_ADD functionality in PHP, so I have taken the function provided on the official PHP website at the "strtotime" <a href="http://php.net/manual/de/function.strtotime.php" rel="nofollow">documentation page</a> like follows:</p>

<pre><code>function get_x_months_to_the_future( $base_time = null, $months = 1 )
{
    if (is_null($base_time))
        $base_time = time();

    $x_months_to_the_future    = strtotime( "+" . $months . " months", $base_time );

    $month_before              = (int) date( "m", $base_time ) + 12 * (int) date( "Y", $base_time );
    $month_after               = (int) date( "m", $x_months_to_the_future ) + 12 * (int) date( "Y", $x_months_to_the_future );

    if ($month_after &gt; $months + $month_before)
        $x_months_to_the_future = strtotime( date("Ym01His", $x_months_to_the_future) . " -1 day" );

    return $x_months_to_the_future;
} //get_x_months_to_the_future()
</code></pre>

<p>It works perfectly, but I don't understand why in the $month_before and $month_after calculation the year is multiplied by 12 in both cases. What difference does that make and is that really needed? I simply don't know why and would like to understand that code completely.</p>
