2

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 advance!

2
  • You should remove the leading 0 from "07". mktime expects integers but will interpret leading zeros as a string and can yield unexpected results. Commented Jul 11, 2011 at 17:48
  • Thx everyone!! Simple solution..^^ I must have read a wrong documentation when implementing it.. Or maybe I just read wrong.. ;) Thank you all for your quick answers!! Commented Jul 11, 2011 at 17:49

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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 ]]]]]]] )

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.