Question

I have two web servers with different operating system.

SERVER 1 run in Centos 5 with LAMP Server. PHP Version 5.3.21

SERVER 2 run in openSUSE 11.3 with LAMP Server. PHP Version 5.3.5

Both PHP Configurations are same. Some are the default.

I have a php file with code like this:

<?php
/* TEST STRTOTIME */
echo "<br /><br />".strtotime("2038-01-01");
echo "<br /><br />".strtotime("2039-01-01");
?>

When i run this file in SERVER 1, the result is :

2145934800

2177470800

but when i run this file in SERVER 2, the second conversion does not produce anything. Only show result is :

2145891600

Why the results of the conversion on both servers give different values​​? whereas the same file. Why on SERVER 2 could not convert on the above date 2038-01-01? Is there a solution to this problem?

Was it helpful?

Solution

Your remote server is probably 32-bit. You will need to have a 64-bit server to process dates after roughly 2038.

The reason is your remote server stores its integers as signed 32 bit integers. The maximum number that can be stored as a signed 32 bit integer is 2,147,483,647 (2^31 - 1). Since this number is the number of seconds after Jan 1st, 1970 (Unix epoch), you can see that the number will eventually be exhausted (and possibly overflow if not bounds checked).

Example

Image Source: Wikipedia

OTHER TIPS

From the manual for DateTime

The date and time information is internally stored as a 64-bit number so all conceivably useful dates (including negative years) are supported. The range is from about 292 billion years in the past to the same in the future.

Also, strtotime() has too many inconsistencies to be reliable. I would always recommend using DateTime instead.

$dt = DateTime::createFromFormat('Y-m-d', '2039-01-01');
echo $dt->getTimestamp();

You can check the timezones of your servers.

Also you can set a default timezone using the date_default_timezone_set('UTC'); command.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top