# mktime 2-digit vs 4-digit year

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
the mktime() year argument expects an integer
how does it know if I passed a 2-digit vs 4 digit value?
testing  0 <= year < 100 simply isn't good enough... what If I want to
specify years 0000 - 0099 (which should be possible on a 64-bit
system)
What keeps them from being being interpreted as 1970-2069?  Or do
they?
(I don't have a 64-bit system to test on)

And if it does correctly accept the year 0000 - 0099, how could my own
code distinguish between 0000 and 00 ?

## Re: mktime 2-digit vs 4-digit year

mktime was not designed to do that. 0-99 are interpreted as 2 digits. mktime
accepts 2 or 4 digit year. valid range is from 1901 and 2038 on 32-bit
system so you can't even interpret anything outside of that range. it is
Year 2038 problem - http://en.wikipedia.org/wiki/Year_2038_problem

for anything outside of that range you probably need to make your own
library.

You can't. 0000 == 00. so 00 - 99 is simply an alias for 1900-1999.

## Re: mktime 2-digit vs 4-digit year

That's just it, I don't know how it would be possible to code in
straight PHP
unless it accepted a string for the year" "0000" - "0099" and use
strlen()

I've created a datetime_mktime() func that uses the DateTime class and
DateTime::add / DateTime::sub to create the date thus avoiding the 32-
bit limitation on 32-bit systems.
It takes the same args as mktime()   it'd be nice if it were able to
accept 00-99 and know that's referring to 1970-2069 and also accept
0000-0099

## Re: mktime 2-digit vs 4-digit year

Executive decision on my part.
If you pass 85 to my function it will be interpreted literally as year
85 (not 1985)
however, It'll also accept strings for the year.   "85" will be
interpreted as 1985.  In case someone needs that 2-digit
functionality.

What bonehead is using 2-digit years?!  :)

## Re: mktime 2-digit vs 4-digit year

mktime is more like a port of 32bit c++ version of mktime which functions
has the same valid range.
but in c++ there is also mktime64 for ages which i haven't seen in php.

so there is nothing bonehead... it's just how it is made to work. accept it
or find some alternative how to do it.