Fixed negative values processing in add_months()
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 26 Mar 2011 09:44:44 +0000 (10:44 +0100)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 26 Mar 2011 09:44:44 +0000 (10:44 +0100)
includes/date_functions.inc

index ee37f000e377039d076ca45bb60bc64f3c1510ae..e4b2c76f0f5644e895c52cd018fa3c3bc2feff02 100644 (file)
@@ -267,9 +267,9 @@ function add_months($date, $months) // accepts negative values as well
        global $date_system;
     list($day, $month, $year) = explode_date_to_dmy($date);
 
-       $month += $months;
-       $year += ($month-1)/12;
-       $month = ($month-1)%12 + 1;
+       $months += $year*12+$month;
+       $month = ($months-1)%12+1;
+       $year = ($months-$month)/12;
 
        $timet = mktime(0,0,0, $month, min($day, days_in_month($month, $year)), $year);