Bug #51096 [Com]: strtotime returns wrong results

[email protected] ("wayne530 at gmail dot com") Wed, 31 Mar 2010 21:12:43 +0200 (CEST)
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at http://bugs.php.net/bug.php?id=51096&edit=1

 ID:               51096
 Comment by:       wayne530 at gmail dot com
 Reported by:      phpbugs at rizzt dot kicks-ass dot org
 Summary:          strtotime returns wrong results
 Status:           Assigned
 Type:             Bug
 Package:          Date/time related
 Operating System: linux
 PHP Version:      5.2.12
 Assigned To:      derick

 New Comment:

@derick can you comment on what exactly should be the behavior of
strtotime('-1 
month') or strtotime('last month')?

today 3/31/10  date('Y-m-d', strtotime('-1 month')) returns
'2010-03-03'
               date('Y-m-d', strtotime('+1 month')) returns
'2010-05-01'

-1 month seems to offset by 28 days.  +1 month seems to offset by 31
days.  is 
this correct behavior?


Previous Comments:
------------------------------------------------------------------------
[2010-03-31 15:32:08] [email protected]

@marques: You're wrong, that's perfectly correct behaviour for last
month/previous month. It is also unrelated to this report.

------------------------------------------------------------------------
[2010-03-31 15:14:20] marques at displague dot com

This one is a clearer case of strtotime being bad:

echo date("Y-m-d",strtotime("february", strtotime("march 31 2010")));
2010-03-03

------------------------------------------------------------------------
[2010-03-31 14:33:37] marques at displague dot com

I'm not sure there would be consensus on my expected return values here,
but it 
makes more sense then getting March as a result.

Reproduce code:
---------------
date_default_timezone_set('America/New_York');
echo date(DATE_RFC822,strtotime('march 31 2010 -1 month'));
echo date(DATE_RFC822,strtotime('march 30 2010 -1 month'));
echo date(DATE_RFC822,strtotime('march 29 2010 -1 month'));
echo date(DATE_RFC822,strtotime('march 28 2010 -1 month'));


Expected result:
----------------
Sun, 28 Feb 10 00:00:00 -0500
Sun, 28 Feb 10 00:00:00 -0500
Sun, 28 Feb 10 00:00:00 -0500
Sun, 28 Feb 10 00:00:00 -0500


Actual result:
----------------
Wed, 03 Mar 10 00:00:00 -0500
Tue, 02 Mar 10 00:00:00 -0500
Mon, 01 Mar 10 00:00:00 -0500
Sun, 28 Feb 10 00:00:00 -0500

------------------------------------------------------------------------
[2010-03-31 14:23:58] marques at displague dot com

This may be fodder for another bug report, but strtotime() more
specifically 
"returns wrong results" for the last three days of March 2010.

date_default_timezone_set('America/New_York');
echo PHP_VERSION."\n".
  date(DATE_RFC822)."\n".
  date(DATE_RFC822,strtotime('last month'));

5.3.1
Wed, 31 Mar 10 08:21:30 -0400
Wed, 03 Mar 10 08:21:30 -0500

This was also posted as a PHP.net comment: 
http://www.php.net/manual/en/function.strtotime.php#97065

------------------------------------------------------------------------
[2010-03-09 09:49:36] [email protected]

Re-opening because of the question marks:

firstdayof = 'first day of'?;
lastdayof = 'last day of'?;

It shouldn't cause an issue though, but it needs fixing.

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


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=51096


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