It\'s kind of a silly question, but what would be the maximum INT value of a time()
and it\'s future date, e.g.
1st January 2999
PHP stores the highest integer number it can represent in the PHP_INT_MAX
constant:
date('Y-m-d H:i:s', PHP_INT_MAX); // 2038-01-19 04:14:07
If you want to work with dates beyond that, consider using the DateTime API, e.g.
$dt = new DateTime('1st January 2999');
$dt->add(DateInterval::createFromDateString('+1 day'));
echo $dt->format('Y-m-d H:i:s'); // 2999-01-02 00:00:00
echo $dt->format('U'); // 32472226800
DateTime seems to use 32bit on 64bit servers, too. So you get into trouble.
I've solve it this way:
new DateTime("99999/12/31 00:00:00");
Because, the date overflows the maximum length for DateTime, date use the maximum possibel value and returns a DateTime-object like this (inspected with var_dump) :
object(DateTime)#9 (3) { ["date"]=> string(19) "2031-09-12 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } }
I'm not sure if it differs with the versions of PHP. I've tested it with version 5.4.
The shortest way I know is to get tomorrow's date:
date("Y-n-j", strtotime("+1 day"))
date("Y-n-j", PHP_INT_MAX)
on 64bit-systems gives potential dangerous value: 292277026596-12-4
The last 32-Bit Integer timestamp will be reached January 19, 2038. This is known as the Year 2038 problem.
Remember, the Y2038 problem does not apply on 64-bit systems.
On 64-bit platforms PHP_INT_MAX
does not reflect maximum INT value for 32-bit platforms. Here's how to get it:
$max32bitInt = PHP_INT_SIZE == 4 ? PHP_INT_MAX : PHP_INT_MAX>>32;
If you're always using 64-bit platform, just use:
PHP_INT_MAX>>32