Page 1 of 1

mktime Problems

Posted: Tue Aug 28, 2007 3:25 am
by shiznatix
So I get in a date, lets say this date is 09/07/2007 as in July 9th 2007. Now when I try to mktime with this by doing:

Code: Select all

die(date('m-d-Y', mktime(1, 1, 1, 07, 09, 2007)));

//output: 06-30-2007
which is obviously wrong. If I remove the leading 0 from the 09 then I get the correct output. The leading 0 infront of the 7 does not affect getting a correct output though. So really, what the heck?

I have been trying to come up with a way to remove the leading 0 from an int but without avail. The only thing I came up with was turning it into a string then getting the intval() from that but thats so silly. I have tried multiplying it by 1, casting it as an int, getting the intval, but nothing. And why does this leading 0 screw things up so badly in the first place?

Posted: Tue Aug 28, 2007 4:19 am
by volka
A leading 0 marks the number as being octal, 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20
09 is an invalid octal number -> 0

Posted: Tue Aug 28, 2007 4:55 am
by shiznatix
but is there a function to take the 09 and turn it into 9 without turning it into a string then an int?

Posted: Tue Aug 28, 2007 5:09 am
by VladSun
Where do you get this 09 value from?