|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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?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