Bug->Req #66988 [Nab]: Modifying a time -1 month from the end of the month has unexpected results
| From: | jglw at live dot co dot uk | Date: | Mon, 31 Mar 2014 20:13:20 +0000 |
| Subject: | Bug->Req #66988 [Nab]: Modifying a time -1 month from the end of the month has unexpected results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184988@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66988&edit=1
ID: 66988
User updated by: jglw at live dot co dot uk
Reported by: jglw at live dot co dot uk
Summary: Modifying a time -1 month from the end of the month
has unexpected results
Status: Not a bug
-Type: Bug
+Type: Feature/Change Request
Package: Date/time related
Operating System: Windows 7
PHP Version: 5.4.26
Block user comment: N
Private report: N
New Comment:
Might I suggest that you could set in the php.ini something like date.overflow to true or false,
defaulting to true. If false it would give the last day of the month in these cases.
Previous Comments:
------------------------------------------------------------------------
[2014-03-31 16:26:23] requinix@php.net
"-1 month" works by literally subtracting 1 from the month. The resulting date 2014-02-31
overflows to 2014-03-03.
There is no solution to the -1 problem that satisfies everyone. If you need it to become 2014-02-28
then apply a bit more logic: if the two months are the same then use the last day of the previous
month instead.
------------------------------------------------------------------------
[2014-03-31 15:53:10] jglw at live dot co dot uk
Description:
------------
If you modify a time -1 month from the last day of a month it seems to interpret that as take away
the number of days from the previous month. It would make more sense that if you modified a time by
-1 month it wouldn't fall into the same month from which you modified it.
Test script:
---------------
<?php
$time = strtotime("2014-03-31 -1 month");
echo date("Y-m-d", $time);
?>
Expected result:
----------------
2014-02-28
Actual result:
--------------
2014-03-03
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66988&edit=1