Bug #76175 [Nab]: date function not working properly for Feb month
| From: | ansari dot sohail2013 at gmail dot com | Date: | Thu, 05 Apr 2018 07:34:55 +0000 |
| Subject: | Bug #76175 [Nab]: date function not working properly for Feb month | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214609@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76175&edit=1
ID: 76175
User updated by: ansari dot sohail2013 at gmail dot com
Reported by: ansari dot sohail2013 at gmail dot com
Summary: date function not working properly for Feb month
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows
PHP Version: 7.0.29
Block user comment: N
Private report: N
New Comment:
But -1 month should substract by month not by -30 days
Previous Comments:
------------------------------------------------------------------------
[2018-04-02 05:59:19] requinix@php.net
30-03-2018 - 1 month = 30-02-2018 which overflows to 02-03-2018.
30-03-2018 - 2 months = 30-01-2018 which does not need to overflow.
If your application requires special handling around the beginning or end of months then you need to
write code for it.
------------------------------------------------------------------------
[2018-04-02 05:49:55] ansari dot sohail2013 at gmail dot com
Description:
------------
$d = '30-03-2018';
echo date('Y-m', strtotime('-1 month '.$d));// should give 2018-02
echo date('Y-m', strtotime('-2 month '.$d));// this gives 2018-01
Output:
2018-03
2018-01
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76175&edit=1