|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 09:00:01 2025 UTC |
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. --PierreJust 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".