Bug #26565 [Csd]: strtotime('this month') resolving to the wrong month?
| From: | rasmus@php.net | Date: | Wed, 30 Mar 2011 20:39:24 +0000 |
| Subject: | Bug #26565 [Csd]: strtotime('this month') resolving to the wrong month? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159859@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=26565&edit=1
ID: 26565
Updated by: rasmus@php.net
Reported by: michaelw at darkhorse dot com
Summary: strtotime('this month') resolving to the wrong
month?
Status: Closed
Type: Bug
Package: Date/time related
Operating System: Mac OS X 10.2.x
PHP Version: 4.3.4
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
To the people adding comments about +-1 month here. This really isn't a
bug. Read the link Derick provided:
http://derickrethans.nl/obtaining-the-next-month-in-php.html
It doesn't matter if you are going ahead 1 month or back 1 month. The
logic is the same. It tries to find Feb.30 which doesn't exist, so
instead of walking backwards to Feb.28 it assumes you meant 2 days after
Feb.28 which is obviously in March. Like I said in the comments at that
link, for better or worse, this is the UNIX convention for time
manipulation. Most UNIX tools will behave exactly like this. In order to
do this correctly, you should be specifying a day in the month as Derick
suggests in that post.
Previous Comments:
------------------------------------------------------------------------
[2011-03-30 22:01:12] rbredlau at broadlux dot com
I am having the exact same error as fortizma.
<?php
$runtm = time();
$month = strtotime( '-1 month', $runtm );
$ts = date( 'n/j/Y g:i a', $runtm );
$ts2 = date( 'n/j/Y g:i a', $month );
$last = date( 'Y-m-F', $month );
echo $ts . PHP_EOL . $ts2 . PHP_EOL . $last . PHP_EOL . PHP_EOL;
Produces:
3/30/2011 12:56 pm
3/2/2011 12:56 pm
2011-03-March
PHP 5.2.14-0.dotdeb.0 with Suhosin-Patch 0.9.7 (cli) (built: Jul 25 2010
08:53:19)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with NuSphere PhpExpress v2.0.3, Copyright (c) 2002-2009 NuSphere
Corp., by Dmitri Dmitrienko
with DBG v3.9.2, (C) 2000,2010, by Dmitri Dmitrienko
cat /etc/issue
Ubuntu 9.04 \n \l
------------------------------------------------------------------------
[2011-03-30 20:28:48] fortizma at gmail dot com
Derik, thanks for your reply, but in my last reply, I'm talking about
last month,
no next month.
Thanks in advance.
------------------------------------------------------------------------
[2011-03-30 19:48:40] derick@php.net
http://derickrethans.nl/obtaining-the-next-month-in-php.html
------------------------------------------------------------------------
[2011-03-30 19:45:35] fortizma at gmail dot com
Based on the current date which is march 30, 2011.
if I try echo date('Y-m-d', strtotime('-1 months')); I would expect
2011-02-28,
but what I'm getting is 2011-03-02.
Do this occur due to 2011 is not a leap year?
------------------------------------------------------------------------
[2003-12-10 09:06:48] sniper@php.net
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=26565
--
Edit this bug report at http://bugs.php.net/bug.php?id=26565&edit=1