Bug #75012 [Opn->Nab]: strtotime('-x month') has an unexpected behavior

From: Date: Mon, 31 Jul 2017 21:05:58 +0000
Subject: Bug #75012 [Opn->Nab]: strtotime('-x month') has an unexpected behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210437@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75012&edit=1 ID: 75012 Updated by: derick@php.net Reported by: paladinotoldo at gmail dot com Summary: strtotime('-x month') has an unexpected behavior -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: any PHP Version: 7.0.21 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php "-X month" just removes X from the month number. "-1 month" with 2017-07-31 makes it 2017-06-31, which does not exist, and hence rolls over to 2017-07-01. This is expected and proper behaviour. See also: https://twitter.com/rasmus/status/892070940648943616 Previous Comments: ------------------------------------------------------------------------ [2017-07-31 20:57:47] paladinotoldo at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.strtotime --- strtotime('-1 month') has an unexpected behavior in 31th day of month Test script: --------------- $t =strtotime('31-07-2017'); echo "\n". date('d/m/Y',$t ); $timestamp = strtotime('-1 month',$t ); echo "\n".date("d/m/Y", $timestamp); $timestamp = strtotime('-2 month',$t ); echo "\n". date("d/m/Y", $timestamp); $timestamp = strtotime('-3 month',$t ); echo "\n". date("d/m/Y", $timestamp); $timestamp = strtotime('-4 month',$t ); echo "\n". date("d/m/Y", $timestamp); $timestamp = strtotime('-5 month',$t ); echo "\n". date("d/m/Y", $timestamp); Expected result: ---------------- 31/07/2017 30/06/2017 31/05/2017 30/04/2017 31/03/2017 28/02/2017 or 31/07/2017 01/07/2017 01/06/2017 02/05/2017 02/04/2017 03/03/2017 Actual result: -------------- 31/07/2017 01/07/2017 31/05/2017 01/05/2017 31/03/2017 03/03/2017 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75012&edit=1

« previous php.bugs (#210437) next »