note 94693 added to datetime.diff

From: Date: Wed, 18 Nov 2009 22:32:06 +0000
Subject: note 94693 added to datetime.diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-163046@lists.php.net to get a copy of this message
The DateInterval format unfortunately leads to inconsitencies: <?php $start = new DateTime('2009-01-01 00:00:00'); // 31 days $time_span = $start->diff(new DateTime('2009-02-01 00:00:00')); var_dump($time_span); // returns '1 month' $start = new DateTime('2009-02-01 00:00:00'); //28 days $time_span = $start->diff(new DateTime('2009-03-01 00:00:01')); var_dump($time_span); // returns '1 month' ?> Of course it is possible to guess what does DateTime mean for a month, but in such case the invoking program should take care of month lengths and leap years (imagine counting days between dates years appart) - DateTime class is supposed to do that. In my opinion this function should return a value in seconds (or any other stable unit). Afterwards the program would have to convert the value as needed, but the value would be exact. ---- Server IP: 190.2.55.64 Probable Submitter: 200.123.125.47 ---- Manual Page -- http://www.php.net/manual/en/datetime.diff.php Edit -- https://master.php.net/note/edit/94693 Del: integrated -- https://master.php.net/note/delete/94693/integrated Del: useless -- https://master.php.net/note/delete/94693/useless Del: bad code -- https://master.php.net/note/delete/94693/bad+code Del: spam -- https://master.php.net/note/delete/94693/spam Del: non-english -- https://master.php.net/note/delete/94693/non-english Del: in docs -- https://master.php.net/note/delete/94693/in+docs Del: other reasons-- https://master.php.net/note/delete/94693 Reject -- https://master.php.net/note/reject/94693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163046) next »