|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47846 Error in DateTime class when initialising with '2009-02'
Submitted: 2009-03-31 08:44 UTC Modified: 2009-04-08 01:00 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: brooksie155 at yahoo dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.2CVS-2009-03-31 (snap) OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: brooksie155 at yahoo dot com
New email:
PHP Version: OS:


 [2009-03-31 08:44 UTC] brooksie155 at yahoo dot com
There is a bug in the constructor of this object if you are only specifying the month and the year when dealing with the month of February.

Reproduce code:
$date = new DateTime('2009-02');
echo $date->format('Y-m');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-31 08:56 UTC]
Not a bug.  As documented, this defaults to now and you can override individual components in the constructor.  In your case you have chosen Feb. 2009, but didn't specify a day of the month.  PHP picks todays day, which is the 31st day of the month.  The 31st day of Feb will fall in March since Feb doesn't have 31 days.
 [2009-03-31 08:56 UTC]
I can not reproduce this, what does the following output:

$str = "2009-02";
echo date_default_timezone_get(), "\n";
var_dump( date_parse( $str ) );
$date = new DateTime( $str );
echo $date->format( DateTime::ISO8601 ), "\n";
 [2009-03-31 09:01 UTC]
Just as a comment to Rasmus, that's not true. The format "2009-02" implicitly sets the day nr as 1.
 [2009-03-31 09:11 UTC]
The output from your script on my box:

array(12) {
  array(0) {
  array(0) {

That 'false' there on the date will make it default to today's date.  Seeing it on both 5.2 and 5.3 on Freebsd.  
 [2009-04-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 06:03:34 2021 UTC