PHP MySQL date_add fonksiyonu

0 Cevap

Ben PHP MySQL date_add işlevselliğini uygulamak gerekiyor, bu yüzden documentation page gibi "strtotime" adresindeki resmi PHP web sitesinde sağlanan işlevi izler almış:

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 > $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()

Bu mükemmel çalışır, ancak $ month_before ve $ month_after hesaplanmasında yıl her iki durumda da 12 ile çarpılır neden anlamıyorum. Ne fark yapmak ve gerçekten gerekli olduğunu mı? Ben sadece neden bilmiyorum ve tamamen bu kodu anlamak istiyorum.

0 Cevap