Bug #62193 [Opn->Nab]: strtotime returning wrong month
| From: | aharvey@php.net | Date: | Fri, 31 May 2013 18:10:57 +0000 |
| Subject: | Bug #62193 [Opn->Nab]: strtotime returning wrong month | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179257@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62193&edit=1
ID: 62193
Updated by: aharvey@php.net
Reported by: thomasrothwell dot 1990 at gmail dot com
Summary: strtotime returning wrong month
-Status: Open
+Status: Not a bug
Type: Bug
-Package: *Data Exchange functions
+Package: Date/time related
Operating System: Ubuntu 12.04 LTS & Ubuntu 10.04
PHP Version: 5.3Git-2012-05-31 (Git)
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
PHP date functions will overflow out of bound values: since June 31 doesn't
exist, it becomes July 1.
Previous Comments:
------------------------------------------------------------------------
[2013-05-31 15:29:50] phpbugs at theHiltons dot net
Reproduced May 31st, 2013, CentOS 64Bit, PHP 5.4.15:
foreach (['Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'] as $monthName) {
echo "getdate(strtotime('$monthName'))['month'] = " .
getdate(strtotime($monthName))['month'] . "\n";
echo "getdate(strtotime('$monthName'))['mon'] = " .
getdate(strtotime($monthName))['mon'] . "\n";
}
------------------------------------------------------------------------
[2012-05-31 02:25:24] thomasrothwell dot 1990 at gmail dot com
Assuming the issue is related to June only having 30 days, which then pushes it to the next month
July.
<?php
2 //Expected 30/06
3 echo date('d/m', strtotime('+1 MONTH'));
4 //Result 01/07
5
6 //Expected 30/06
7 echo gmdate('d/m', strtotime('+1 MONTH'));
8 //Result 01/07
9
10 //Expected 01/06
11 echo date('d/m', strtotime('first day of +1 month'));
12 //Result 01/06
Could be safe to assume that the function should check the limits of each month to prevent it from
going past the extreme.
------------------------------------------------------------------------
[2012-05-31 02:10:51] thomasrothwell dot 1990 at gmail dot com
Description:
------------
Came across the wrong month being returned when using the following:
<?php echo date('m', strtotime('+1 MONTH')); ?>
Expected: 06
Result: 07
I've only noticed this occur Today (31st of May 2012).
Altered my php.ini to use the following config as well:
date.timezone = "Australia/Sydney"
date.default_latitude = -35.308142
date.default_longitude = 149.124518
Thinking it could be a timezone issue. Also attempted use of gmdate.
What I found to work was:
<?php echo date('m', strtotime('first day of +1 month')); ?>
Expected: 06
Result: 06
Test script:
---------------
<?php
//Expected 06
echo date('m', strtotime('+1 MONTH'));
//Result 07
//Expected 06
echo gmdate('m', strtotime('+1 MONTH'));
//Result 07
//Expected 06
echo date('m', strtotime('first day of +1 month'));
//Result 06
Expected result:
----------------
060606
Actual result:
--------------
070706
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62193&edit=1