php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28581 mktime bugg
Submitted: 2004-05-30 17:49 UTC Modified: 2004-06-02 11:03 UTC
From: s_svene at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.0 OS: Windows
Private report: No CVE-ID: None
 [2004-05-30 17:49 UTC] s_svene at hotmail dot com
Description:
------------
I have noticed a bug in the commando date("m",mktime(0,0,0,x);
You get the same result if you type in a 2 or a 3 where X belong, that is the nuber of the current month.


Reproduce code:
---------------
<?php
    echo("Month 2 : ");
    echo(date("m",mktime(0,0,0,2)."<br>");
    echo("Month 3");
    echo(date("m",mktime(0,0,0,3)."<br>");
?>

Expected result:
----------------
Month 2 : 2
Month 3 : 3

Actual result:
--------------
Month 2 : 3
Month 3 : 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-30 19:13 UTC] pajoye@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Works here with 4.3.6 and snapshots (4 and 5, linux&win32)

--Pierre
 [2004-05-30 20:14 UTC] s_svene at hotmail dot com
I have tried 5.0 to, and i can't get it to work..
going to try 4.6 to but.
 [2004-05-30 20:51 UTC] pajoye@php.net
Btw, I was silly enough to do not have seen that:

echo(date("m",mktime(0,0,0,3)."<br>");
should be:
echo date("m<b\r>",mktime(0,0,0,3));

If you like to test it, use only mktime or:
 date('m', mktime(0,0,0,$m));

Bogus anyway, it works with both php5 and php4.

--Pierre
 [2004-06-02 11:03 UTC] mgf@php.net
When you don't feed mktime() a day, it uses the equivalent value from the current date.  The original post was made on 30th May. Please check the documentation to see what mktime() makes of a request for 30th Feb.

Definitely not a PHP bug.
 [2016-06-30 16:59 UTC] armahillo at gmail dot com
Just verifying that this behavior is still happening in v7.1  (and also 5.5.9, both Ubuntu envs)

How is this not a bug? The default day argument should not cause unintended side effects with the month. 

php > echo date('M', mktime(1,1,1,2));
Mar
php > echo date('M', mktime(1,1,1,3));
Mar

I should not need to do this just to get it to work:
php > echo date('M', mktime(1,1,1,2,1));
Mar

Otherwise why even allow there to be optional arguments in the first place? If I'm omitting the day, that's implying that the day is irrelevant, so we should be using a default day that exists in ALL months, not the current day (ie. you could use any of 1-28 and it would be fine)

mktime() should never return a result that invalidates an explicitly provided argument. If "today's day, but in that month" is the desired default behavior, then an edge case should be added that traps "this day doesn't exist in that month, so default to day 1".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 13 01:00:03 2025 UTC