php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76069 date_diff
Submitted: 2018-03-08 15:32 UTC Modified: 2018-03-12 15:46 UTC
From: pustka-phpnet at lkn dot pl Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.1.15 OS: windows
Private report: No CVE-ID: None
 [2018-03-08 15:32 UTC] pustka-phpnet at lkn dot pl
Description:
------------
---
From manual page: http://www.php.net/function.date-diff
---
In some cases date_diff() function shows differenece in days instead of months.

Test script:
---------------
$dateS = new DateTime('2018-03-01');
$dateE = new DateTime('2018-04-01');
print_r(date_diff($dateS, $dateE));

$dateS = new DateTime('2018-02-01');
$dateE = new DateTime('2018-03-01');
print_r(date_diff($dateS, $dateE));

Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 1
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 31
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)
DateInterval Object
(
    [y] => 0
    [m] => 1
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 28
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Actual result:
--------------
DateInterval Object
(
    [y] => 0
    [m] => 1
    [d] => 3//why 3?
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 31
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)
DateInterval Object
(
    [y] => 0
    [m] => 0//why 0?
    [d] => 28//and why 28?
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 28
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-08 17:11 UTC] jhdxr@php.net
-Package: *General Issues +Package: Date/time related
 [2018-03-12 15:36 UTC] cmb@php.net
-Status: Open +Status: Critical -Assigned To: +Assigned To: cmb
 [2018-03-12 15:36 UTC] cmb@php.net
This looks like being a duplicate of bug #65003.
 [2018-03-12 15:46 UTC] cmb@php.net
-Status: Critical +Status: Duplicate
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Feb 27 14:01:30 2020 UTC