strtotime fails

A

Anonymous

Guest
The following code shows that strtotime appears to work up to 2075 but not from 2076 onwards. I find it hard to believe. Sorry if I am missing something obvious.

for ($i = 2000; $i <= 2100; $i++)
{
$PWD_S = $i."0331";
$PWD_E = strtotime($PWD_S);
echo "<p>strtotime($PWD_S): $PWD_E</p>";
}

reults in:-

strtotime(20740331): 2147483647

strtotime(20750331): 2147483647

strtotime(20760331): -1

strtotime(20770331): -1

Can anyone explain my problem please.
 
Just noticed the result is the same for both years!

Then noticed:

strtotime(20360331): 2090548800

strtotime(20370331): 2122084800

strtotime(20380331): 2147483647

strtotime(20390331): 2147483647

It seems to fail at 2037.

It looks like some type of rollover problem but ....
 
Well as no one was willing to give advice. I was forced to figure it out myself. Its the roll over of a 32 bit signed integer. That occurs at 2147483647 seconds from the Unix epoch.

That makes PHP a bit of a problem for anyone using future dates past 2037!

A rather dramatic problem for PHP.

As PHP appears to have no 64 bit integers. This will probably only be fixed when the default server loads are 64 bit.

So if you are planning on working out mortgages, insurance policies, climate trend models. Watch out. Those blokes who screwed up the year 2000 are at it again!

Does anyone have a proper way to deal with this before I wave this forum goodbye due to lack of support.
 
Back
Top