|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-05-04 10:33 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 00:00:01 2025 UTC |
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.