note 100380 rejected from datetime.diff by danbrown

From: Date: Tue, 12 Oct 2010 16:09:12 +0000
Subject: note 100380 rejected from datetime.diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173161@lists.php.net to get a copy of this message
Note Submitter: alves dot josea at gmail dot com ---- 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 ?>

« previous php.notes (#173161) next »