Bug #51737 [Opn->Asn]: Having a bug when using date_diff($t1,$t2)
| From: | aharvey@php.net | Date: | Tue, 04 May 2010 09:11:08 +0000 |
| Subject: | Bug #51737 [Opn->Asn]: Having a bug when using date_diff($t1,$t2) | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4302@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51737&edit=1
ID: 51737
Updated by: aharvey@php.net
Reported by: iggukk at gmail dot com
Summary: Having a bug when using date_diff($t1,$t2)
-Status: Open
+Status: Assigned
Type: Bug
-Package: Date/time related
+Package: Documentation problem
Operating System: Win XP
PHP Version: 5.3.2
-Assigned To:
+Assigned To: aharvey
New Comment:
Not a bug, since you probably want %a (which is the total number of days
in the interval) rather than %d.
%d only shows the number of days left over after date_diff() has
calculated the number of months and years: in your first example, the
interval is basically "1 month 0 days", so %d returns 0. (If you try "%m
month(s) %d day(s)" as the format string, that will probably be a bit
clearer.)
Nevertheless, the documentation could probably be a touch clearer on
this point. Morphing into a documentation bug; I'll see if I can make it
a bit more obvious in one of the examples what %d does.
Previous Comments:
------------------------------------------------------------------------
[2010-05-04 11:04:01] iggukk at gmail dot com
Huh, sorry about that, and thanks for answering so quickly.
echo $interval->format('%R%d days');
simply from the example on php manual.
Just tried to feed the dates in different formats like 12.04.2010 and
12.03.2010, (instead of 2010-04-12) it seems to give the same result in
final.
------------------------------------------------------------------------
[2010-05-04 10:57:43] aharvey@php.net
The test script you've provided doesn't work, since echoing a
DateInterval object isn't supported. How are you actually outputting
$interval?
------------------------------------------------------------------------
[2010-05-04 10:33:23] iggukk at gmail dot com
Description:
------------
Hi,
Sorry if not posting this bug in the correct section. I'm currently
having a bug when using date_diff().
Seems that when the "day" part of the dates is the same on both dates
compared, the function returns "0 Days" instead of 30 or some Days.
Test script:
---------------
$datetime1 = date_create('2010-03-08');
$datetime2 = date_create('2010-04-08');
$interval = date_diff($datetime1,$datetime2);
echo $interval;
//=> returns "+0 Days"
//
//Whereas
//
$datetime1 = date_create('2010-03-08');
$datetime2 = date_create('2010-04-07');
$interval = date_diff($datetime1,$datetime2);
echo $interval;
//Will return "+30 Days"
Expected result:
----------------
Should return "a whole month" interval like +31 Days in that particular
case.
Actual result:
--------------
returns +0 Days
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51737&edit=1