php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53741 DateTime, date_create, strtotime - wrong result on realtive date time string
Submitted: 2011-01-13 17:24 UTC Modified: 2011-01-14 11:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: metwo at gmx dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.17 OS: inux 2.6.36.3 x86_64
Private report: No CVE-ID: None
 [2011-01-13 17:24 UTC] metwo at gmx dot net
Description:
------------
parsing of relative date/time string "midnight first day last month" returns a wrong result in php 5.2.17

Test script:
---------------
<?php

print_r(date_create('midnight first day last month'));
print $d->format('Y-m-d H:i:s') . "\n";
print date('Y-m-d H:i:s', strtotime('midnight first day last month'));


Expected result:
----------------
// relative to current date/time - 2011-01-13 17:23

DateTime Object
(
    [date] => 2010-12-01 00:00:00
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)
2010-12-01 00:00:00
2010-12-01 00:00:00


Actual result:
--------------
// relative to current date/time - 2011-01-13 17:23

DateTime Object
(
)
2010-12-14 00:00:00
2010-12-14 00:00:00


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-14 04:47 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-01-14 04:47 UTC] aharvey@php.net
5.2 is no longer supported.
 [2011-01-14 11:30 UTC] derick@php.net
And it's not a bug either. "midnight", "first day" and "last month" are all separate items.
                                      2011-01-13 17:23
"midnight" resets the time to 00:00:  2011-01-13 00:00
"first day" adds a day:               2011-01-14 00:00
"last month" removes a month:         2011-12-14 00:00

In PHP 5.3 you can do:
"midnight first day of last month" where "midnight", "first day of" and "last month" are the tokens:
                                      2011-01-13 17:23
"midnight" resets the time to 00:00:  2011-01-13 00:00
"last month" removes a month:         2011-12-14 00:00
"first day of" resets day to 1:       2011-12-01 00:00
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 15:01:28 2025 UTC