|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-03-22 02:52 UTC] nfoskett at internode dot on dot net
Description:
------------
When using "first day of" relative time formats, the constructor gives inconsistent values for what ought to be the same. Results shown below are all as of 2020-03-22 03:49:52.
Test script:
---------------
$month_start = new DateTime("first day of this month");
echo $month_start->format('Y-m-d H:i:s') . "\n";
$month_start = new DateTime("first day of March");
echo $month_start->format('Y-m-d H:i:s') . "\n";
https://3v4l.org/lG3GL
Expected result:
----------------
2020-03-01 00:00:00
2020-03-01 00:00:00
or possibly
2020-03-01 03:49:52
2020-03-01 03:49:52
Actual result:
--------------
2020-03-01 03:49:52
2020-03-01 00:00:00
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
Interesting little bug. Looking at the date parsing code, it appears that this code only works by accident: new DateTime("first day of this month") This actually returns the exact same result: new DateTime("first day of this year")