Bug #76175 [Nab]: date function not working properly for Feb month

From: Date: Thu, 05 Apr 2018 09:45:13 +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-214611@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 Updated by: requinix@php.net 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: And that's exactly what it did: subtract one month. But there is no such thing as the 30th of February. Read what I said again. Previous Comments: ------------------------------------------------------------------------ [2018-04-05 07:34:54] ansari dot sohail2013 at gmail dot com But -1 month should substract by month not by -30 days ------------------------------------------------------------------------ [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

« previous php.bugs (#214611) next »