php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50879 mktime: wrong handling for month 2 without day parameter
Submitted: 2010-01-29 11:16 UTC Modified: 2010-01-29 13:30 UTC
From: lehn at planet-ic dot de Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.12 OS: Linux
Private report: No CVE-ID: None
 [2010-01-29 11:16 UTC] lehn at planet-ic dot de
Description:
------------
mktime produces wrong month for february if no day parameter given.

Reproduce code:
---------------
echo strftime("%B(%m)\n",mktime(0,0,0,2));
echo strftime("%B(%m)\n",mktime(0,0,0,2,1));

Expected result:
----------------
February(02)
February(02)

Actual result:
--------------
March(03)
February(02)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-29 12:51 UTC] aharvey@php.net
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

If the day parameter is omitted when calling mktime(), the current day is used. Since today is the 29th of January, and February only has 28 days this year, this effectively results in the first call being mktime(0, 0, 0, 2, 29), and Feburary 29 is implicitly converted to March 1.
 [2010-01-29 13:30 UTC] lehn at planet-ic dot de
Thank you for your fast reply. I looked the manual twice before but i overlooked the default value of '$day = date("j")'. 

This kind of problems only happen in the last few days of a month, maybe a eye catching warning on the manual will help.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 23 11:00:03 2025 UTC