Bug #66988 [Opn->Nab]: Modifying a time -1 month from the end of the month has unexpected results
| From: | requinix@php.net | Date: | Mon, 31 Mar 2014 16:26:24 +0000 |
| Subject: | Bug #66988 [Opn->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-184986@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
Updated by: requinix@php.net
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: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows 7
PHP Version: 5.4.26
Block user comment: N
Private report: N
New Comment:
"-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.
Previous Comments:
------------------------------------------------------------------------
[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