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

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
foobaa
Forum Commoner
Posts: 40
Joined: Tue Feb 13, 2007 10:36 am

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

Post by foobaa »

Hi,

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

Thanks
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

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

Post 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:~$
 
foobaa
Forum Commoner
Posts: 40
Joined: Tue Feb 13, 2007 10:36 am

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

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post by Mark Baker »

User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

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

Post 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:~$
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post 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.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

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

Post 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.
Post Reply