Bug #76038 [Com]: strtotime returning wrong date on -1 month
Edit report at https://bugs.php.net/bug.php?id=76038&edit=1
ID: 76038
Comment by: Wes dot example at example dot org
Reported by: diego at agudo dot eti dot br
Summary: strtotime returning wrong date on -1 month
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows / Linux
PHP Version: 7.2.2
Block user comment: N
Private report: N
New Comment:
I don't see how the suggested behavior is more correct than the current one.
When doing "month math" you are supposed to ignore the days, since months have different
lengths.
Previous Comments:
------------------------------------------------------------------------
[2018-03-01 14:28:13] diego at agudo dot eti dot br
Description:
------------
strtotime returning wrong date on -1 month
Test script:
---------------
$data = '2018-03-31';
print_r($data);
echo "\n\n";
$data = strtotime($data);
print_r($data);
echo "\n\n";
$data = date("Y-m-d", $data);
print_r($data);
echo "\n\n";
$data = strtotime($data);
print_r($data);
echo "\n\n";
$data = date("Y-m-d", strtotime('-1 month', $data));
print_r($data);
echo "\n\n";
Expected result:
----------------
2018-02-28
Actual result:
--------------
2018-03-03
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76038&edit=1
Thread (5 messages)