note 96646 added to datetime.diff

From: Date: Tue, 09 Mar 2010 19:23:24 +0000
Subject: note 96646 added to datetime.diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-166842@lists.php.net to get a copy of this message
@andarin2 It's important to note that this class exists to smooth out some of the inconsistencies in the calendar itself. Months are not a fixed number of days, but range from 28 to 31 days, so going from 2-1-2009 to 3-1-2009 is one calendar month and people will call it as such. That's why you have this return 1 month for both of your examples. If you really want the number of seconds returned, use mktime() instead and simply subtract the smaller date from the larger one. <?php $diff=mktime(0,0,0,3,1,2009) - mktime(0,0,0,2,1,2009); //now $diff has the number of seconds between the two days $days=$diff/86400; //$days=28 ?> So we know that 28 days is the difference between the two dates but that doesn't help us if we need to know how many months that is ---- Server IP: 192.41.40.227 Probable Submitter: 209.168.200.20 ---- Manual Page -- http://www.php.net/manual/en/datetime.diff.php Edit -- https://master.php.net/note/edit/96646 Del: integrated -- https://master.php.net/note/delete/96646/integrated Del: useless -- https://master.php.net/note/delete/96646/useless Del: bad code -- https://master.php.net/note/delete/96646/bad+code Del: spam -- https://master.php.net/note/delete/96646/spam Del: non-english -- https://master.php.net/note/delete/96646/non-english Del: in docs -- https://master.php.net/note/delete/96646/in+docs Del: other reasons-- https://master.php.net/note/delete/96646 Reject -- https://master.php.net/note/reject/96646 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166842) next »