Edit report at https://bugs.php.net/bug.php?id=63863&edit=1
ID: 63863
Comment by: grandfelix at gmail dot com
Reported by: brian dot feaver at sellingsource dot com
Summary: DateTime:setDate() date not used after modify("last
day of...")
Status: Closed
Type: Bug
Package: Date/time related
Operating System: Mac OS X
PHP Version: 5.3.20
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This is still not fixed as it was said. Example below still does not work as expected.
$firstDayInMonth = new DateTime('first day of january');
echo $firstDayInMonth->setDate(date('Y'), 1,
date('d'))->format('Y-m-d');
Outputs:
2017-01-01
PHP: 7.0.6-3
Previous Comments:
------------------------------------------------------------------------
[2016-06-29 17:34:26] cmb@php.net
This issue has been fixed as of PHP 5.6.19 and 7.0.4, see
<https://3v4l.org/ATGLp> and <https://3v4l.org/H3jZY>.
------------------------------------------------------------------------
[2016-05-26 03:48:53] php dot net at multiwebinc dot com
This seems to happen only when using certain relative formats to create the DateTime object, such as
'last day of next month' or 'first day of this month', however 'last sat of
July 2008' *does not* cause the error.
------------------------------------------------------------------------
[2016-05-03 16:21:44] php-bugs at allenjb dot me dot uk
This also happens after using a "descriptive string" in the constructor:
$dtEnd = new \DateTime("last day of last month");
var_dump($dtEnd);
$dtEnd = $dtEnd->setDate(2016, 04, 03);
var_dump($dtEnd);
3v4l.org shows this bug appears to be in all versions of PHP 5 + 7 to date.
------------------------------------------------------------------------
[2015-10-30 04:45:47] whitearchey at gmail dot com
A simple workaround:
$date->modify('+0 day');
------------------------------------------------------------------------
[2014-06-25 11:01:34] gsdev at me dot com
Hi,
This is happening on Mac OS X 10.8.5
PHP 5.5.0 (cli) (built: Jun 21 2013 12:09:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0-dev, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
It looks to be working in PHP 5.2 but broke in PHP 5.3 onwards.
http://3v4l.org/H3jZY
<?php
date_default_timezone_set('UTC');
$date = new DateTime(null, new DateTimeZone('UTC'));
$date->setTime(0,0,0);
$date->modify('next month');
$date->modify('last day of this month');
$date->setDate(2014, 1, 21);
// This should be 21st Jan 2014
echo $date->format('Y-m-d');
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=63863
--
Edit this bug report at https://bugs.php.net/bug.php?id=63863&edit=1