开发者

php date function returns wrong date

I have a php script which includes the date() function. But somehow it messes the day names up.

the line is as simple as

date ("l",mktime(0,0,0,$test3,$test2,$test4));

When I test it with a current date e.g.

date ("l",mktime(0,0,0,11,07,2011));

it returns the correct day, Monday. But if I go just one day further

date ("l",mktime(0,0,0,12,07,2011));

it returns Wednesday..

Do you have any idea where the problem might be? Anything with timezone or so..? I've never used the date function before and couldn't find any solution googeling it or in here..

I appreciate any answer! thx in adv开发者_StackOverflowance!


The fourth parameter of mktime() is the month. November 7, 2011 is a Monday, but December 7, 2011 is a Wednesday.

int mktime (
    [ int $hour = date("H") 
    [, int $minute = date("i") 
    [, int $second = date("s") 
    [, int $month = date("n") 
    [, int $day = date("j") 
    [, int $year = date("Y") 
    [, int $is_dst = -1 ]
    ]]]]]] )

Additionally, you should remove leading zeros where present ( 07 => 7 ) to avoid unexpected errors.

From: http://www.php.net/mktime


You are changing the month not the day

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )


As odd as it may seem, the PHP documentation says the fourth parameter is actually the month (11 or 12 in your example), while the fifth (07) is the day. Try switching those and trying again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜