php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45661 Error in mktime when omitting day
Submitted: 2008-07-31 00:47 UTC Modified: 2008-07-31 07:16 UTC
From: frozenfire at thefrozenfire dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.6 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2008-07-31 00:47 UTC] frozenfire at thefrozenfire dot com
Description:
------------
There is a bug in mktime, where omission of the day parameter causes some issues.

Most notably, when attempting to iterate through months. See the reproduction code for a better explanation.

Reproduce code:
---------------
// Bugged code. Produces "Mar" twice.
for($i=1; $i<13; $i++) echo date('M', mktime(0, 0, 0, $i))."\n";

// Working code. Produces intuitive output.
for($i=1; $i<13; $i++) echo date('M', mktime(0, 0, 0, $i, 0))."\n";

Expected result:
----------------
Jan
Feb
Mar
Apr
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Actual result:
--------------
Jan
Mar
Mar
Apr
Jun
Jul
Aug
Sep
Oct
Nov
Dec

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-31 01:21 UTC] frozenfire at thefrozenfire dot com
// Working code. Produces intuitive output.
// Original bug report used 0 as 5th param
for($i=1; $i<13; $i++) echo date('M', mktime(0, 0, 0, $i, 1))."\n";
 [2008-07-31 07:16 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

http://bugs.php.net/bug.php?id=11212
http://bugs.php.net/bug.php?id=44073
http://bugs.php.net/bug.php?id=44577
http://bugs.php.net/bug.php?id=43169
http://bugs.php.net/bug.php?id=41386
http://bugs.php.net/bug.php?id=38279
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 13:01:31 2024 UTC