strtotime('this month') resolving to the wrong month?
| Bug #26565 | strtotime('this month') resolving to the wrong month? | ||||
|---|---|---|---|---|---|
| Submitted: | 2003-12-09 13:09 UTC | Modified: | 2011-03-30 23:38 UTC | ||
| From: | michaelw at darkhorse dot com | Assigned: | derick (profile) | ||
| Status: | Closed | Package: | Date/time related | ||
| PHP Version: | 4.3.4 | OS: | Mac OS X 10.2.x | ||
| Private report: | No | CVE-ID: | None | ||
[2003-12-09 13:09 UTC] michaelw at darkhorse dot com
Description:
------------
strtotime adds an extra month when using the phrase
"this month" or "next month". Using '+1 months' or '+0
months' works fine, though.
And, no, I'm not adding a month to 'Jan. 30'.
Reproduce code:
---------------
echo date('Y-m-d', strtotime('last month'));
echo date('Y-m-d', strtotime('this month'));
echo date('Y-m-d', strtotime('next month'));
echo date('Y-m-d', strtotime('-1 months'));
echo date('Y-m-d', strtotime('+0 months'));
echo date('Y-m-d', strtotime('+1 months'));
Expected result:
----------------
2003-11-09
2003-12-09
2004-01-09
2003-11-09
2003-12-09
2004-01-09
Actual result:
--------------
2003-11-09
2004-01-09
2004-02-09
2003-11-09
2003-12-09
2004-01-09
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2003-12-09 14:37 UTC] sniper@php.net
[2003-12-10 05:57 UTC] mgf@php.net
[2003-12-10 09:06 UTC] sniper@php.net
[2011-03-30 19:45 UTC] 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?[2011-03-30 19:48 UTC] derick@php.net
-Assigned To: +Assigned To: derick
[2011-03-30 20:28 UTC] fortizma at gmail dot com
[2011-03-30 22:01 UTC] 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 22:39 UTC] rasmus@php.net
[2011-03-30 23:34 UTC] fortizma at gmail dot com
[2011-03-30 23:38 UTC] derick@php.net
-Block user comment: No +Block user comment: Yes