note 31911 added to function.date

From: Date: Thu, 08 May 2003 16:40:53 +0000
Subject: note 31911 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-47705@lists.php.net to get a copy of this message
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); } -- http://www.php.net/manual/en/function.date.php http://master.php.net/manage/user-notes.php?action=edit+31911 http://master.php.net/manage/user-notes.php?action=delete+31911 http://master.php.net/manage/user-notes.php?action=reject+31911

« previous php.notes (#47705) next »