php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71511 Diff for februari not a month
Submitted: 2016-02-03 13:38 UTC Modified: 2017-04-24 15:54 UTC
From: efrkool at live dot nl Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 5.6.17 OS: CentOS Linux release 7.2.1511 (C
Private report: No CVE-ID: None
 [2016-02-03 13:38 UTC] efrkool at live dot nl
Description:
------------
When calculating the number of months between the 1st of februari and the 1st of march I espect it to return 1 month but it returns 0.

I first tought this had to do with the leap year but that doesn't have anything to do with it becouse it also happens for 2015.

 

Test script:
---------------
<?php

$first = new \DateTime('2016-02-01 00:00:00', new \DateTimeZone('Europe/Amsterdam'));
$second = new \DateTime('2016-03-01 00:00:00', new \DateTimeZone('Europe/Amsterdam'));

$diff = $first->diff($second);

echo $diff->format('%m') . PHP_EOL;
// Expect: 1, got 0

$second->modify('+1 month');
$diff2 = $first->diff($second);

echo $diff2->format('%m') . PHP_EOL;
// Expect: 2, got 2



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-24 15:54 UTC] heiglandreas@php.net
-Status: Open +Status: Duplicate
 [2017-04-24 15:54 UTC] heiglandreas@php.net
This seems to be a duplicate of https://bugs.php.net/bug.php?id=52480
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC