Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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.

like image 399
Jason Avatar asked Feb 05 '12 21:02

Jason


People also ask

How do you get a date from Strtotime?

Code for converting a string to date$time_input = strtotime ( "2011/05/21" ); $date_input = getDate ( $time_input );

Why is Strtotime return false?

If the date string isn't understood by strtotime() then it will return false. When this happens you can try a few things to force strtotime() to parse the date correctly. Sometimes it's something as simple as swapping the slashes for dashes, which forces strtotime() to parse the date in a different way.

How does Strtotime work in PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

How do I use Strtotime?

If you want to use the PHP function strtotime to add or subtract a number of days, weeks, months or years from a date other than the current time, you can do it by passing the second optional parameter to the strtotime() function, or by adding it into the string which defines the time to parse.


1 Answers

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.

like image 172
TimWolla Avatar answered Sep 28 '22 00:09

TimWolla