Page 1 of 1

Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 10:40 am
by foobaa
Hi,

Does anyone know of any good replacements for time(), date() and mktime() that can handle dates beyond the year 2038?

Thanks

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 10:47 am
by Mirge
foobaa wrote:Hi,

Does anyone know of any good replacements for time(), date() and mktime() that can handle dates beyond the year 2038?

Thanks
Why doesn't date() work beyond 2038?

Code: Select all

mike@mike-kubuntu:~$ php -q test.php
Sep 04, 2109
mike@mike-kubuntu:~$ cat test.php
<?php
 
print date("M d, Y", strtotime("+100 years")) . "\n";
 
?>
mike@mike-kubuntu:~$
 

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 10:54 am
by foobaa
I tried inputting date('jmY', 2678227200) and it returned 1901 where as it should be 2054. I'm using PHP5.3 on Ubuntu 8.

I've just found this:

http://phplens.com/phpeverywhere/adodb_date_library

Which extends all of PHP's related functions.

Cheers

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 10:59 am
by Mark Baker

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 10:59 am
by Mirge
foobaa wrote:I tried inputting date('jmY', 2678227200) and it returned 1901 where as it should be 2054. I'm using PHP5.3 on Ubuntu 8.

I've just found this:

http://phplens.com/phpeverywhere/adodb_date_library

Which extends all of PHP's related functions.

Cheers

Code: Select all

 
mike@mike-kubuntu:~$ php -a
Interactive shell
 
php > print date("m/d/Y", 2678227200);
11/13/2054
php >
 
mike@mike-kubuntu:~$ php -v
PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 23 2009 14:37:14)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
mike@mike-kubuntu:~$

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 11:00 am
by Mark Baker
Mirge wrote:Why doesn't date() work beyond 2038?
Depends whether you're running on a 32-bit or a 64-bit platform.

Re: Code to replace time(), date() and mktime() beyond 2038?

Posted: Fri Sep 04, 2009 11:07 am
by Mirge
Mark Baker wrote:
Mirge wrote:Why doesn't date() work beyond 2038?
Depends whether you're running on a 32-bit or a 64-bit platform.
Ahh you're right. I ran it on a 32-bit platform (same snippet I pasted above) and it returned 1918 for the year.