Edit report at http://bugs.php.net/bug.php?id=51446&edit=1
ID: 51446 Comment by: scspl dot pravin at gmail dot com Reported by: marques at displague dot com Summary: strtotime(last month) should always give the previous month in results Status: Bogus Type: Bug Package: Date/time related PHP Version: 5.3.2 Block user comment: N Private report: N New Comment: Hi, I am converting '12-31-2011' To 2011-12-31 using Function echo date('Y-m-d',strtotime('12-31-2011')); But it is not working. Thanks Pravin Previous Comments: ------------------------------------------------------------------------ [2010-03-31 17:45:13] der...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. . ------------------------------------------------------------------------ [2010-03-31 17:10:20] marques at displague dot com Description: ------------ strtotime("last month") should always return a date in the previous month. Instead, the algorithm seems to return the current day minus the number of days in the previous month. If the number of days in the previous month is less than the current day of the month then the current day of the month days should be subtracted. I realize that Bug #50682, Bug #27793, Bug #27786, Bug #22486 are related, but I do not believe that PHP is strictly implementing the strtotime() as it exists elsewhere and is in a position to provide a better experience. Just as "last day" and "first day" were added in PHP 5.3 there is room for improvement. Implementations are not ubiquitous as MySQL, for example, provides "2010-02-28" when given 'select "2010-03-31" - interval 1 month;'. This is the sort of behavior I would expect from PHP's strtotime(). Test script: --------------- date_default_timezone_set('America/New_York'); print_r(array( date(DATE_RFC822,strtotime("last month", strtotime("january 31 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("february 28 2010"))), date(DATE_RFC822,strtotime('march 28 2010 -1 month')), date(DATE_RFC822,strtotime('march 29 2010 -1 month')), date(DATE_RFC822,strtotime('march 30 2010 -1 month')), date(DATE_RFC822,strtotime('march 31 2010 -1 month')), date(DATE_RFC822,strtotime("last month", strtotime("april 30 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("may 31 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("june 30 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("july 31 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("august 31 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("september 30 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("october 31 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("november 30 2010"))), date(DATE_RFC822,strtotime("last month", strtotime("december 31 2010"))), date(DATE_RFC822,strtotime('last month', strtotime("march 29 2012"))), )); Expected result: ---------------- Array ( [0] => Thu, 31 Dec 09 00:00:00 -0500 [1] => Sun, 31 Jan 10 00:00:00 -0500 [2] => Sun, 28 Feb 10 00:00:00 -0500 [3] => Sun, 28 Feb 10 00:00:00 -0500 [4] => Sun, 28 Feb 10 00:00:00 -0500 [5] => Sun, 28 Feb 10 00:00:00 -0500 [6] => Wed, 31 Mar 10 00:00:00 -0500 [7] => Fri, 30 Apr 10 00:00:00 -0400 [8] => Mon, 31 May 10 00:00:00 -0400 [9] => Wed, 30 Jun 10 00:00:00 -0400 [10] => Sat, 31 Jul 10 00:00:00 -0400 [11] => Tue, 31 Aug 10 00:00:00 -0400 [12] => Thu, 30 Sep 10 00:00:00 -0400 [13] => Sun, 31 Oct 10 00:00:00 -0400 [14] => Tue, 30 Nov 10 00:00:00 -0500 [15] => Wed, 29 Feb 12 00:00:00 -0500 ) Actual result: -------------- Array ( [0] => Thu, 31 Dec 09 00:00:00 -0500 [1] => Thu, 28 Jan 10 00:00:00 -0500 [2] => Sun, 28 Feb 10 00:00:00 -0500 [3] => Mon, 01 Mar 10 00:00:00 -0500 [4] => Tue, 02 Mar 10 00:00:00 -0500 [5] => Wed, 03 Mar 10 00:00:00 -0500 [6] => Tue, 30 Mar 10 00:00:00 -0400 [7] => Sat, 01 May 10 00:00:00 -0400 [8] => Sun, 30 May 10 00:00:00 -0400 [9] => Thu, 01 Jul 10 00:00:00 -0400 [10] => Sat, 31 Jul 10 00:00:00 -0400 [11] => Mon, 30 Aug 10 00:00:00 -0400 [12] => Fri, 01 Oct 10 00:00:00 -0400 [13] => Sat, 30 Oct 10 00:00:00 -0400 [14] => Wed, 01 Dec 10 00:00:00 -0500 [15] => Wed, 29 Feb 12 00:00:00 -0500 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51446&edit=1