PHP date having year 2038 issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rl9088
Forum Newbie
Posts: 1
Joined: Fri Aug 14, 2009 4:54 pm

PHP date having year 2038 issues

Post 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"));
}
 
 
?>
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: PHP date having year 2038 issues

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP date having year 2038 issues

Post 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 ~]$
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP date having year 2038 issues

Post by jackpf »

Just wondering, what happens when we get to 2039 8O ?

Will we all have to have at least 64 bit systems?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP date having year 2038 issues

Post by Eran »

are you kidding? there will be no more 32bit CPUs in about 5 years, except in legacy systems
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP date having year 2038 issues

Post by jackpf »

Yeah...but maybe some of us might want to stay a bit retro :P
Post Reply