RE: [PHP] Difference between months

From: Date: Wed, 26 Mar 2003 01:19:36 +0000
Subject: RE: [PHP] Difference between months
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-141049@lists.php.net to get a copy of this message
> How do I subtract the difference of months between two dates? > > For instance, if one date is 2003-12 and the other is 2002-08, I need to > know that there are 16 months between them. If one date is 2003-04 and the > other is 2003-01, I need to know that there are 3 months between them. How > can I do this? One way... $date1 = "2003-12"; $date2 = "2002-08"; $d1 = explode('-',$date1); $d2 = explode('-',$date2); $diff = ($d1[0]*12+$d1[1]) - ($d2[0]*12+$d2[1]); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#141049) next »