php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46861 mktime returns the wrong number of days for November.
Submitted: 2008-12-14 03:27 UTC Modified: 2008-12-25 01:00 UTC
Votes:3
Avg. Score:1.7 ± 0.9
Reproduced:0 of 2 (0.0%)
From: john at designingforbusiness dot com Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.2.8 OS: OS X, Ubantu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: john at designingforbusiness dot com
New email:
PHP Version: OS:

 

 [2008-12-14 03:27 UTC] john at designingforbusiness dot com
Description:
------------
While using date("d", mktime(0,0,0,11+1,0,2008); to retrieve the number of days in November I continually have 29 returned. While December and other months are correct.

Reproduce code:
---------------
foreach($this->vacationDays as $entry) {
    $nowdate = split("/", $entry[1]);
    $ourDate = mktime(0,0,0,(int)$nowdate[0],(int)$nowdate[1],(int)$nowdate[2]);
    $ourMonth = date("M", $ourDate);
    $ourDay	= date("D", $ourDate);
    $ourYear = date("o", $ourDate);
    $firstDayOfMonth = mktime(0,0,0, $nowdate[0], 1 , $nowdate[2]);
    $firstDayInMonth = date("D", $firstDayOfMonth);
    $daysInMonth = date("d", mktime(0,0,0,(int)($nowdate[0]+1), 0, (int)$nowdate[2]));
    $day_of_week = $firstDayInMonth;
								
    switch($day_of_week) {
	case "Sun": $blank = 0; break;
	case "Mon": $blank = 1; break;
	case "Tue": $blank = 2; break;
	case "Wed": $blank = 3; break;
	case "Thu": $blank = 4; break;
	case "Fri": $blank = 5; break;
	case "Sat": $blank = 6; break;
    }
				
    if(isset($currentMonth) && $ourMonth != $currentMonth) {
	$currentMonth = $ourMonth;
			
	$this->startCalendarMonth($ourMonth, $ourYear);
		
	$day_count = $this->shootBlanks($blank);
		
        for($day_num = 1; $day_num <= $daysInMonth; $day_num++)
        {							
            echo "<td>$day_num</td>";
            $day_count++;
            if($day_count > 7) {
	        echo "</tr>\n    <tr>";
	        $day_count = 1;
            }
        }
	$this->endCalendar();
    }


Expected result:
----------------
The expected result is that November 2008 would return 30 days and December 2008 return 31 days.  

Actual result:
--------------
The current result is Nov 2008 returns 29 days and December 2008 returns 31.  Clearly the problem is with November.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-17 02:47 UTC] jani@php.net
Ever heard of date("t") ?
 [2008-12-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC