|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76785 DateTime construction with a negative year argument shows different behaviours
Submitted: 2018-08-23 15:29 UTC Modified: 2022-06-05 14:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: thijs at tsjeng dot nl Assigned: derick (profile)
Status: Wont fix Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-08-23 15:29 UTC] thijs at tsjeng dot nl
DateTime object instantiation with negative input string via 
'createFromFormat' and same argument just as construction argument display weird behaviour. 

Test script:
var_dump(DateTime::createFromFormat('Y-m-d', '0045-01-01')); // works
var_dump(DateTime::createFromFormat('Y-m-d', '-0045-01-01')); //  false
var_dump(DateTime::createFromFormat('-Y-m-d', '-0045-01-01')); // works, but year is positive instead of negative

var_dump(new DateTime('0045-01-01')); // works
var_dump(new DateTime('-0045-01-01')); // works
var_dump(new DateTime('0045/01/01')); // works

var_dump(new DateTime('-0045/01/01')); // exception


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-23 17:10 UTC]
Fortunately 'U' already supports signed numbers so extending that to 'Y' shouldn't be difficult.
 [2018-11-28 14:19 UTC] bjoern dot fischer at dezem dot de
We are affected by this issue too.

It can be easily reproduced here:
 [2020-01-20 17:35 UTC]
-Assigned To: +Assigned To: derick
 [2020-01-20 17:35 UTC]
This maybe should be reclassified as a Feature request, leaving Derick to decide about it.
 [2021-04-06 18:40 UTC]
-Type: Bug +Type: Feature/Change Request
 [2022-06-05 14:25 UTC]
-Status: Assigned +Status: Wont fix
 [2022-06-05 14:25 UTC]
I am marking this as "won't fix". If you are still interested in having this feature, please file a new issue at with a well defined and explained use case.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 05:01:28 2024 UTC