note 31911 deleted from function.date by sniper

From: Date: Sat, 11 Oct 2003 16:53:50 +0000
Subject: note 31911 deleted from function.date by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58291@lists.php.net to get a copy of this message
Note Submitter: loconet at hotmail dot com ---- For those wanting to calculate the months difference between two dates, this function takes days into consideration. echo monthsApart("2002-07-12","2003-01-01"); //output: 6 echo monthsApart("2002-12-31","2003-01-01"); //output: 0 function monthsApart($oldDate,$newDate) { list($oldYear,$oldMonth,$oldDay) = split("-",$oldDate); list($newYear,$newMonth,$newDay) = split("-",$newDate); $diff = (($newDay >= $oldDay ? 0 : -1) + ($newYear - $oldYear)* 12) + $newMonth - $oldMonth; return abs($diff); }

« previous php.notes (#58291) next »