Req #66988 [Nab->Wfx]: Modifying a time -1 month from the end of the month has unexpected results

From: Date: Mon, 31 Mar 2014 20:25:36 +0000
Subject: Req #66988 [Nab->Wfx]: 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-184990@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: derick@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: Not a bug +Status: Wont fix Type: Feature/Change Request Package: Date/time related Operating System: Windows 7 PHP Version: 5.4.26 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2014-03-31 20:25:01] derick@php.net No settings for this, that makes for unportable scripts. Often, when you do -1 month, you are really not interested in the date itself, but just in the month. In which case you can use "first day of last month" or "first day of -2 months". And if you want the last day of the previous month, then you can use "last day of last month". ------------------------------------------------------------------------ [2014-03-31 20:13:19] jglw at live dot co dot uk Might I suggest that you could set in the php.ini something like date.overflow to true or false, defaulting to true. If false it would give the last day of the month in these cases. ------------------------------------------------------------------------ [2014-03-31 16:26:23] requinix@php.net "-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. ------------------------------------------------------------------------ [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

« previous php.bugs (#184990) next »