|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 05:00:01 2025 UTC |
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