note 51422 added to function.date
| From: | php-general at lists dot php dot net | Date: | Wed, 30 Mar 2005 18:11:27 +0000 |
| Subject: | note 51422 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87189@lists.php.net to get a copy of this message | ||
It seems that there is some thing wrong with this date( ) function. The following is my code. I want
to get the "month" of last month and the "month" before last month in my
application. However, for the "month" before last month, the result is correct, for the
last month, the result is curent month( obviously, it is wrong ). I did not find this problem before
only today (Mar 30, 2005).
$currentmonth = date("Y-m-d",mktime(0, 0, 0, date("m"), date("d"),
date("Y")));
$lastmonth = date("Y-m-d", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));
$pre2month = date("Y-m-d", mktime(0, 0, 0, date("m")-2, date("d"),
date("Y")));
echo ' this month: '.$currentmonth.' || last month'.$lastmonth.' lastlast
month: '.$pre2month;
this month: 2005-03-30 || last month2005-03-02 lastlast month: 2005-01-30
However, if I change date("d") to 1, the results are correct. I think this is perhaps a
small bug in the computation of the time in the mktime( ).
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51422
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51422&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51422&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51422&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51422&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51422&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51422&report=yes
Search -- http://master.php.net/manage/user-notes.php