ID: 22957 Updated by: [EMAIL PROTECTED] Reported By: jacques dot daguerre at st dot com -Status: Closed +Status: Bogus Bug Type: Date/time related Operating System: Linux RedHat 6.2/7.3 PHP Version: 4.3.1 New Comment:
"Closed" means we fixed something. There was never anything to fix here, hence Bogus. Previous Comments: ------------------------------------------------------------------------ [2003-03-31 09:43:18] jacques dot daguerre at st dot com The case is closed ------------------------------------------------------------------------ [2003-03-31 09:25:34] [EMAIL PROTECTED] There is no bug here. You are asking for the timestamp for February 31st. What is it supposed to do? Read your mind and figure out you want the last day of February? That's impossible. It does the only sensible thing and gives you the actual date 31 days beyond Feb.1. If you want the last day of a month, get the 1st of the following month and subtract a day. ------------------------------------------------------------------------ [2003-03-31 05:43:38] [EMAIL PROTECTED] This behaviour is already fully documented at http://www.php.net/manual/en/function.mktime.php, which also gives a one-liner for finding the last day of any month (see Example 2). ------------------------------------------------------------------------ [2003-03-31 05:16:32] jacques dot daguerre at st dot com It was probably not a bug after all and I probably had my code bugged for many months without noticing it until yesterday... I probably misunderstood the way mktime works. If you a day that is greater than the maximum day of the month, then mktime will go for the following month: a date like : mktime (0,0,0,2,31,2003) will be March 03, 2003 even the month entered is February. Since Feb 31 doesn't exist it will consider the (31-28)th day in the following month, and therefore the result of March 03. The calculation of a date a month ago cannot just simply be : $lastmonth1 = mktime (0,0,0,(date('m')-1),date('d'),date('Y')); I corrected my code to be : $now1 = mktime (0,0,0,date("m"),date("d"),date("Y")); $now = date ("Y-m-d", $now1); $today_day= date ("d", $now1); $lastmthday = mktime (0,0,0,date('m'),0,date('Y')); $lastday = date ("d", $lastmthday); if ( $today_day > $lastday) {$prevd = $lastday; }else{$prevd = $today_day;} $lastmonth1 = mktime (0,0,0,(date('m')-1),$prevd,date('Y')); $lastmonth = date ("Y-m-d", $lastmonth1); this will calculate also the last day of the previous month and make the day date of the day will not be a higher number than the last of the previous month. This works fine. I would suggest to post this on the mktime function page as I guess other people could make the mistake as well. ------------------------------------------------------------------------ [2003-03-31 04:27:00] jacques dot daguerre at st dot com for the comment of [EMAIL PROTECTED] $lastmonth1 = mktime (0,0,0,(date('n')-1),date('j'),date('Y')); $lastmonth2 = mktime (0,0,0,(date('m')-1),date('d'),date('Y')); $lastmonth1 and $lastmonth2 are both set to the same value : 1046646000 for today Marh 31st, 2003. The (date('m')-1) calculation works and mktime() doesn't seem to be taking the leading 0's into consideration. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/22957 -- Edit this bug report at http://bugs.php.net/?id=22957&edit=1