Doc #63878 [Com]: date time function issue problem
| From: | mail+php at requinix dot net | Date: | Mon, 31 Dec 2012 21:25:39 +0000 |
| Subject: | Doc #63878 [Com]: date time function issue problem | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9334@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63878&edit=1
ID: 63878
Comment by: mail+php at requinix dot net
Reported by: rupesh dot php at gmail dot com
Summary: date time function issue problem
Status: Open
Type: Documentation Problem
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Take a close look at the documentation for mktime().
day
The number of the day relative to the end of the previous month. [...] Values
greater than the number of days in the relevant month reference the appropriate
day in the following month(s).
When you told it to create a time for "November 31st, 2012" it overflowed the day
number into December. Same for September/October. Likewise if you had it go all
the way back to February it would have given you March 2nd.
Previous Comments:
------------------------------------------------------------------------
[2012-12-31 12:55:58] rupesh dot php at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.date#refsect1-function.date-seealso
---
The date time related functions do not work properly when the current date is 31st of a month, like
today is 31st December 2012.. It seems to be working on a 30 day principle for a month and does not
return the desired output whenever we you a +/- 1month ting with strtotime() function or with a
mktime() function.
The issue is depicted in the script mentioned below with the output that I get.
Script ::
---------
for($i=0; $i<6; $i++)
{
echo date("Y-M-d", mktime(0, 0, 0, date("m")-$i, date("d"),
date("Y")))."<br>";
// or even with
// echo date("Y-M-d",
strtotime("-".$i."day"))."<br>";
}
Outputs ::
----------
2012-Dec-31
2012-Dec-01
2012-Oct-31
2012-Oct-01
2012-Aug-31
2012-Jul-31
instead, it should have been ::
-------------
2012-Dec-31
2012-Nov-30
2012-Oct-31
2012-Sep-30
2012-Aug-31
2012-Jul-31
Note that I have only come across this issue with today being 31st of the month.
Test script:
---------------
for($i=0; $i<6; $i++)
{
echo date("Y-M-d", mktime(0, 0, 0, date("m")-$i, date("d"),
date("Y")))."<br>";
// or even with
// echo date("Y-M-d",
strtotime("-".$i."day"))."<br>";
}
Expected result:
----------------
2012-Dec-31
2012-Nov-30
2012-Oct-31
2012-Sep-30
2012-Aug-31
2012-Jul-31
Actual result:
--------------
2012-Dec-31
2012-Dec-01
2012-Oct-31
2012-Oct-01
2012-Aug-31
2012-Jul-31
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63878&edit=1