Jason
Jason

Reputation: 15355

What would cause php's strtotime to not work for a date in 2099?

I have three servers, doing the following on all three servers:

echo strtotime('2099-12-31');
echo strtotime(date('Y-m-d'));

gets me:

Server #1: (php 5.3.8, 64bit)

4102376400
1328418000

Server 2: (php 5.3.2, 32bit)

**[nothing]**
1328418000

Server #3: (php 5.3.2 - 64bit I thought it might be a php version issue)

4102376400
1328418000

What would cause strtotime to fail on one of the servers but not the others? All three have the same Default timezone and date.timezone settings in php.ini (not sure if that would have an effect or not). I also turned on errors and I'm not seeing anything.

Upvotes: 6

Views: 4510

Answers (2)

TimWolla
TimWolla

Reputation: 32731

Probably it is a 32-bit issue. It works just fine on my 64-Bit Server, but my 32-bit Ubuntu returns false on strtotime('2099-12-31')

For further information see this note in the manual (highlighting by me):

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.

Upvotes: 10

icyrock.com
icyrock.com

Reputation: 28628

As per the docs:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.

Try e.g 2019-12-31, should work as expected.

Upvotes: 2

Related Questions