note 100380 added to datetime.diff

From: Date: Tue, 12 Oct 2010 15:18:22 +0000
Subject: note 100380 added to datetime.diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-173159@lists.php.net to get a copy of this message
Hello! I think the examples are misleading the right answer to calculate the difference in days between 2 dates. At least they mislead me :) You need to use %a format for total amount of days. <?php //Example $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2010-10-13'); //Notice the dates are from different years $interval = $datetime1->diff($datetime2); echo $interval->format('%R%d days'); // +2 days -- i was expecting +367 days instead of +2 days echo $interval->format('%R%a days'); //+367 days ?> ---- Server IP: 81.92.192.129 Probable Submitter: 188.80.55.98 ---- Manual Page -- http://www.php.net/manual/en/datetime.diff.php Edit -- https://master.php.net/note/edit/100380 Del: integrated -- https://master.php.net/note/delete/100380/integrated Del: useless -- https://master.php.net/note/delete/100380/useless Del: bad code -- https://master.php.net/note/delete/100380/bad+code Del: spam -- https://master.php.net/note/delete/100380/spam Del: non-english -- https://master.php.net/note/delete/100380/non-english Del: in docs -- https://master.php.net/note/delete/100380/in+docs Del: other reasons-- https://master.php.net/note/delete/100380 Reject -- https://master.php.net/note/reject/100380 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173159) next »