php.net |  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
Votes:3
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
---
From manual page: http://www.php.net/datetime.add
---
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');




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-11 12:14 UTC] jhdxr@php.net
-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] jhdxr@php.net
https://3v4l.org/VlkYR
 [2017-08-11 13:10 UTC] derick@php.net
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:
https://github.com/derickr/timelib/issues/17
 [2017-08-11 13:11 UTC] derick@php.net
-Assigned To: +Assigned To: derick
 [2017-10-24 05:24 UTC] kalle@php.net
-Status: Verified +Status: Assigned
 [2020-03-19 11:15 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2020-03-19 11:15 UTC] cmb@php.net
Looks like this has been fixed upstream long ago, so this ticket
can be closed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 12:01:36 2025 UTC