note 66676 deleted from function.date by bjori

From: Date: Fri, 26 May 2006 14:20:51 +0000
Subject: note 66676 deleted from function.date by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112333@lists.php.net to get a copy of this message
Note Submitter: minterior at gmail dot com ---- Calculates the number of months between two given dates. Which ones can be in any format accepted by the strtotime. <?php /** * Calcula el número de meses entre dos fechas dadas */ function month_diff( $start_date, $end_date ) { // dates can be in any format accepted by the strtotime function // convert to UNIX timestamps $start_date = strtotime( $start_date ); $end_date = strtotime( $end_date ); $months = 0; $month_seconds = 365.25 * 24 * 3600 / 12; // REAL month seconds if ( $start_date < $end_date ) { $date1 = $start_date; $date2 = $end_date; } else { $date1 = $end_date; $date2 = $start_date; } while ( $date1 <= $date2 ) { $months++; $date1 += $month_seconds; // Add 1 REAL month. } return $months; } ?>

« previous php.notes (#112333) next »