php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65807 DateTime('firstday') creates wrong result
Submitted: 2013-10-02 08:15 UTC Modified: 2014-07-31 13:39 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: a dot schilder at gmx dot de Assigned: salathe (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.5.4 OS: Windows7
Private report: No CVE-ID: None
 [2013-10-02 08:15 UTC] a dot schilder at gmx dot de
Description:
------------
Following the documentation, creating a new DateTime instance with the realtive format "first day" (without month) should result in "the day of the first of the current month" (although it's recommended to use it with the optional month): http://php.net/manual/en/datetime.formats.relative.php

In my tests (also in PHP 5.3.27 and PHP 5.4.7) a wrong date was created. As far as I can see, it's always the current time + 1 day.

Test script:
---------------
<?php
echo PHP_VERSION . "\r\n";
$datetime1 = new DateTime('now');
echo $datetime1->format('Y-m-d H:i:s') . "\r\n";
$datetime2 = new DateTime('first day of this month');
echo $datetime2->format('Y-m-d H:i:s') . "\r\n";
$datetime3 = new DateTime('first day');
echo $datetime3->format('Y-m-d H:i:s') . "\r\n";

Expected result:
----------------
2013-09-30:
5.5.4
2013-09-30 07:59:29
2013-09-01 07:59:29
2013-09-01 07:59:29

2013-10-01:
5.5.4
2013-10-01 07:59:29
2013-10-01 07:59:29
2013-10-01 07:59:29

2013-10-02:
5.5.4
2013-10-02 07:59:29
2013-10-01 07:59:29
2013-10-01 07:59:29

Actual result:
--------------
2013-09-30:
5.5.4
2013-09-30 07:59:29
2013-09-01 07:59:29
2013-10-01 07:59:29

2013-10-01:
5.5.4
2013-10-01 07:59:29
2013-10-01 07:59:29
2013-10-02 07:59:29

2013-10-02:
5.5.4
2013-10-02 07:59:29
2013-10-01 07:59:29
2013-10-03 07:59:29

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-23 23:28 UTC] Rican7 at gmail dot com
Hmm, it seems that this was broken sometime back in 5.3.3...
http://3v4l.org/Cioac
 [2013-12-24 16:57 UTC] salathe@php.net
See bug #51096 [1], which introduced this change into 5.3.3.

[1] https://bugs.php.net/bug.php?id=51096
 [2014-07-31 13:39 UTC] salathe@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: salathe
 [2014-07-31 13:39 UTC] salathe@php.net
Marking as duplicate of bug #67722, this is the older bug but commits were made against the other one.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 10:01:28 2024 UTC