Edit report at http://bugs.php.net/bug.php?id=53212&edit=1

 ID:                 53212
 Updated by:         [email protected]
 Reported by:        karl at crucialp dot com
 Summary:            Date not rolling back one month
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Date/time related
 Operating System:   Centos5 64bit
 PHP Version:        Irrelevant
 Block user comment: N

 New Comment:

Since it is 10-31 where you are, -1 month tries to go back to the 31st
day of 

September, but since there is no 31st day of September, that becomes
Oct.1 

instead.  That's just how strtotime works.  You need to be more precise
when you 

say -1 month.  For example, you could do strtotime('last day of last
month') or 

'first day of 3 months ago', things like that.  But just saying 'last
month' is 

not descriptive enough.


Previous Comments:
------------------------------------------------------------------------
[2010-10-31 04:21:50] karl at crucialp dot com

Description:
------------
Howdy,



This is a php implementation on a cpanel box:

PHP 5.2.9 (cli) (built: Jun  5 2009 04:19:37) 

Copyright (c) 1997-2009 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

    with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by
eAccelerator

    with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by
ionCube Ltd., and

    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend
Technologies

    with Suhosin v0.9.27, Copyright (c) 2007, by SektionEins GmbH

    with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend
Technologies





Today is 2010 - 10 - % and basically I have the following:



$thisMonth = date("Y-m-1");

this will return as expected: 2010-10-1



Then I have this:

$lastmonth = strftime("%Y-%m-1", strtotime("-1 months"));

Which does not return as expected, it returns: 2010-10-1 the same as
above.

Expected result would be: 2010-09-1

However I have tried alternative approaches such as naming.

$lastmonth = strftime("%Y-%m-1", strtotime("-1 month"));

Same thing.



Possible bug?

Test script:
---------------
<?php





echo date("Y-m-1"); //Returns 2010-10-1



echo "<br />";



echo strftime("%Y-%m-1", strtotime("-2 month")); // Returns 2010-08-1



echo "<br />";



echo strftime("%Y-%m-1", strtotime("-1 month")); // Unexpected:
2010-10-1



echo "<br />"; 



echo strftime("%Y-%m-1", strtotime("-1 months")); // Unexpected:
2010-10-1



?>

Expected result:
----------------
I expect that it would return a back roll of on month from the current



At the moment of posting this it is october, so it should roll to
september, delivering results:



2010-09-1





Actual result:
--------------
Well at the moment it is just returning the current month:



2010-10-1






------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53212&edit=1

Reply via email to