Page 1 of 1

PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 5:01 pm
by rl9088
Hi. I am new to PHP. I have code that adds weeks to an original date. It works fine until 01/19/2038. This is a 32-bit issue.

Is there an easy workaround?

My code is as follows:

Code: Select all

<?php
 
$date = '08/14/2009';
$add_weeks = 2;
 
while ($add_weeks < 2000) {
            $add_weeks = $add_weeks + 2;
            echo $new_date . " " . $add_weeks  ."<br>";
            $new_date = date("m/d/Y",strtotime(date("m/d/Y", strtotime($date)) . " +" . $add_weeks ."weeks"));
}
 
 
?>
 

Re: PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 5:52 pm
by aceconcepts
PHP Manual:
The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).
http://uk.php.net/manual/en/function.date.php

Re: PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 5:59 pm
by Weirdan
rl9088 wrote: Is there an easy workaround?
Sure. Use 64bit PHP on 64bit OS:

Code: Select all

 
[weirdan@home ~]$ php q.php| tail
07/26/2047 1982
08/09/2047 1984
08/23/2047 1986
09/06/2047 1988
09/20/2047 1990
10/04/2047 1992
10/18/2047 1994
11/01/2047 1996
11/15/2047 1998
11/29/2047 2000
[weirdan@home ~]$ php -r 'var_dump(PHP_INT_SIZE);'
int(8)
[weirdan@home ~]$
 

Re: PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 6:57 pm
by jackpf
Just wondering, what happens when we get to 2039 8O ?

Will we all have to have at least 64 bit systems?

Re: PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 7:05 pm
by Eran
are you kidding? there will be no more 32bit CPUs in about 5 years, except in legacy systems

Re: PHP date having year 2038 issues

Posted: Fri Aug 14, 2009 11:21 pm
by jackpf
Yeah...but maybe some of us might want to stay a bit retro :P