php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54685 Unexpected output for DATETIME:diff()
Submitted: 2011-05-07 13:05 UTC Modified: 2013-12-06 07:23 UTC
From: ddynamic dot rahul at gmail dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 5.3.6 OS: Windows NT ABC-223D173EDE7 5.1 b
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ddynamic dot rahul at gmail dot com
New email:
PHP Version: OS:

 

 [2011-05-07 13:05 UTC] ddynamic dot rahul at gmail dot com
Description:
------------
---
I've followed all the reported bugs & forums. However, still not got any solution for this. Please help me to fix this bug. 
---
<?php
$datetime1 = new DateTime('2011-05-01');
$datetime2 = new DateTime('2011-05-07');
$interval = $datetime1->diff($datetime2); print_r($interval);
echo $interval->format('%R%a days');
?>

O/P: DateInterval Object ( [y] => 0 [m] => 0 [d] => 6 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 6015 ) +6015 days

The o/p always gives the same unexpected result for any dates. i.e, +6015

Test script:
---------------
<?php
$datetime1 = new DateTime('2011-05-01');
$datetime2 = new DateTime('2011-05-07');
$interval = $datetime1->diff($datetime2); print_r($interval);
echo $interval->format('%R%a days');
?>

Expected result:
----------------
O/P: DateInterval Object ( [y] => 0 [m] => 0 [d] => 6 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 6015 ) +6015 days

Actual result:
--------------
6 days

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-10 04:03 UTC] denis dot beurive at gmail dot com
I confirm the bug on windows 7 :

$date1 = new DateTime("2011-07-03 00:00:00", new DateTimeZone('Europe/Paris'));
$date2 = new DateTime("2011-07-01 00:00:00", new DateTimeZone('Europe/Paris'));
$diff  = $date1->diff($date2);
echo 'diff(' . $date1->format('Y-m-d') . ',' . $date2->format('Y-m-d') . ' ) = ' . $diff->format('%a') . '<br>';

Result : 

diff(2011-07-03,2011-07-01 ) = 6015

Regards,

Denis
 [2011-11-21 14:37 UTC] bandy dot chris at gmail dot com
Related to bug 51184.
 [2013-12-06 07:23 UTC] mike@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC