|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75038 wrong result of Datetime::add
Submitted: 2017-08-04 17:24 UTC Modified: 2020-03-19 11:15 UTC
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: marco dot delcorto at genesi-software dot it Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.6.31 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: marco dot delcorto at genesi-software dot it
New email:
PHP Version: OS:


 [2017-08-04 17:24 UTC] marco dot delcorto at genesi-software dot it
From manual page:
using the script in the example:
  $date = new DateTime('2369-12-30');
  $date->add(new DateInterval('P1D'));
  echo $date->format('Y-m-d');
the result is '2370-01-00' (wrong), instead of '2369-12-31'

Same problem if we use:
  $dateW2 = new DateTime('2369-12-31');
  echo date_format($dateW2, 'Y-m-d');
the result is '2370-01-00' (wrong), instead of '2369-12-31'

Test script:
$date = new DateTime('2369-12-30');
$date->add(new DateInterval('P1D'));
echo $date->format('Y-m-d') . "\n";

$dateW2 = new DateTime('2369-12-31');
echo date_format($dateW2, 'Y-m-d');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-11 12:14 UTC]
-Summary: datetime error +Summary: wrong result of Datetime::add -Status: Open +Status: Verified -Package: *General Issues +Package: Date/time related
 [2017-08-11 12:14 UTC]
 [2017-08-11 13:10 UTC]
This is a bug in timelib - in the formatting of timestamps:

derick@singlemalt:~/dev/timelib/tests $ ./tester-create-ts "2369-12-31" "" "UTC"
TS: 12622694400 | 2369-12-31 00:00:00 UTC UTC

derick@singlemalt:~/dev/timelib/tests $ ./tester-render-ts 12622694400 "UTC"
TYPE: 3 TS: 12622694400 | 2370-01-00 00:00:00 UTC UTC

I have filed a bug upstream:
 [2017-08-11 13:11 UTC]
-Assigned To: +Assigned To: derick
 [2017-10-24 05:24 UTC]
-Status: Verified +Status: Assigned
 [2020-03-19 11:15 UTC]
-Status: Assigned +Status: Closed
 [2020-03-19 11:15 UTC]
Looks like this has been fixed upstream long ago, so this ticket
can be closed.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 01 01:01:24 2020 UTC