php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45509 create_date_from_format() cannot parse negative (BC) dates
Submitted: 2008-07-14 13:29 UTC Modified: 2015-08-28 01:11 UTC
Votes:8
Avg. Score:4.2 ± 0.8
Reproduced:4 of 5 (80.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: tj at systisoft dot com Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 5.3CVS-2008-11-11 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
38 - 22 = ?
Subscribe to this entry?

 
 [2008-07-14 13:29 UTC] tj at systisoft dot com
Description:
------------
While the constructor of DateTime can handle negaive dates (BC dates), create_date_from_format cannot.

Reproduce code:
---------------
$d = new DateTime("-4000-01-31"); echo $d->format("Y-m-d"), PHP_EOL;
$d = date_create_from_format("Y-m-d", "4000-01-31"); echo $d->format("Y-m-d"), PHP_EOL;
$d = date_create_from_format("Y-m-d", "-4000-01-31"); echo $d->format("Y-m-d"), PHP_EOL;

Expected result:
----------------
-4000-01-31
4000-01-31
-4000-01-31

Actual result:
--------------
-4000-01-31
4000-01-31
PHP Fatal error:  Call to a member function format() on a non-object in Command line code on line 3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-28 01:11 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2015-08-28 01:11 UTC] cmb@php.net
Well, the "Y" format specifier expects a four-digit year – so
actually this is not a bug. I'm changing to feature request.
 [2018-12-05 14:15 UTC] bjoern dot fischer at dezem dot de
The documentation of 'create_date_from_format()' says that the identifiers behave like the ones of 'date()'. In 'date()' when format the timestamp for the year 10000, date will output '10000' and not '0000'. So 'Y' is actually a *at least* four-digit year. See: https://3v4l.org/iOHWa

Because of this, I would argue that this actually is a bug.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 19:01:35 2019 UTC