views:

75

answers:

3

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

Would time() ever get to that value? Going for a large time() value would return this:

Thu 1st Jan 1970 1:00AM

A normal int date

1287320788 - outputs today's date: Sun 17th Oct 2010 2:06PM

But I'm only curious for the biggest int date and the last date.

+13  A: 

The last 32-Bit Integer timestamp will be reached January 19, 2038. This is known as the Year 2038 problem.

Pekka
Thanks for this Pekka. Will this ever be solved once we nearly reach to it?
YouBook
@YouBook if PHP still exists by then, probably. It's going to be easy to fix by switching the underlying system to larger INTs - Won't be much of a problem thanks to PHP's weak typing. Alternatively, use `DateTime` as suggested by Gordon
Pekka
@Pekka At the IPC10 I learned that PHP is likely to exist until between 2035 and 2045. It's the next COBOL ;) See here http://it-republik.de/php/news/IPC-Keynote-2010-PHP-End-of-Life-und-was-Ruby-mit-Scala-gemein-hat-057245.html (german)
Gordon
I guess if PHP is intact by 2038, we'll have PHP version 50 :D
YouBook
@Gordon ahahahahahaha! Very nice. Even though also kind of depressing - imagining legacy PHP code still running in 30 years... Some of it still relying on register_globals and magic quotes, which had to be re-introduced in PHP 9 because removing them broke so many production apps...
Pekka
@Pekka yeah, but the positive thing is you probably dont have to worry about a job until you can go into retirement ;)
Gordon
+5  A: 

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
Gordon
Yup, using `DateTime` and - on mySQL side - the `DATETIME` field type fixes the issue completely.
Pekka
Interesting. :) +1
YouBook
A: 

Remember, the Y2038 problem does not apply on 64-bit systems.

oglgog
Mmm, are you sure? Will PHP's internal handling of integers turn to 64-bit automatically?
Pekka
I'm not exactly sure, but it seems to roll over on my box... :-)
oglgog