php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54597 incorrect years for DateTime objects created with 4-digit years
Submitted: 2011-04-24 06:50 UTC Modified: 2011-11-25 15:51 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: kaldari at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.6 OS: MacOS X
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: kaldari at gmail dot com
New email:
PHP Version: OS:

 

 [2011-04-24 06:50 UTC] kaldari at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.construct
---
I'm actually using PHP 5.3.2. Apologies for not testing against 5.3.6.

DateTime objects created with any of the following strings result in incorrect years:
'January 0099' -> 1999
'January 1, 0099' -> 1999
'0099-01' -> 1999

However, all of the following work correctly:
'0099' -> 0099
'0099-01-01' -> 0099
'01-01-0099' -> 0099

I imagine this is due to DateTime parsing 0099 into 99 in the bad examples (and thus triggering the 1900 addition). This bug currently blocks the following MediaWiki bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=28655

Test script:
---------------
$tz = new DateTimeZone("Europe/Amsterdam");
$dateObject = new DateTime( 'January 0099', $tz );
echo $dateObject->format( 'Y' );
$dateObject = new DateTime( 'January 1, 0099', $tz );
echo $dateObject->format( 'Y' );
$dateObject = new DateTime( '0099-01', $tz );
echo $dateObject->format( 'Y' );

Expected result:
----------------
0099
0099
0099

Actual result:
--------------
1999
1999
1999

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-30 22:29 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2011-11-25 15:51 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2011-11-25 15:51 UTC] derick@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC