mktime Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

mktime Problems

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Where do you get this 09 value from?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply