views:

532

answers:

6

Need to be able to use dates beyond the 32-bit timestamp limit so upgraded our server to Windows Server 2003 64-bit version. And running php 5.2.5 64-bit. However still can't use dates beyond the 32-bit limit.

echo strtotime("11-11-2050");

returns nothing.

Running php on IIS 6.0 using C:\WINDOWS\system32\inetsrv\fcgiext.dll

Let me know if I'm missing something. Found Adodb Date Library that will do what I need but i would prefer to use native php functions so I don't have to modify existing code if possible.

Anyone know if it's possible to get this to work on Windows Server 2003 64-bit?

thanks

A: 

PHP does not use a 64-bit time_t on Win32 yet.

TML
The OP said "...so upgraded our server to **Windows Server 2003 64-bit** version..."
Jonathan Sampson
Doesn't change the fact that PHP is compiled to use a 32-bit time_t - the OS doesn't determine this, it's a compile-time determination, and PHP uses a 32-bit value for this.
TML
For the record, I didn't downvote.
Jonathan Sampson
This is the version of php we downloaded and installed. http://www.fusionxlan.com/PHPx64.phpIt's running on 64bit Windows Server 2003 on IIS6.0. Any options for us to get this working?
Jason
Just one: Compile your own 64-bit version of PHP.
TML
A: 

I just tried this on a 32bit machine and this returns false with var_dump:

var_dump strtotime("11-11-2050");

echo returns nothing as false is not displayable. I noticed the php Changelog on http://php.net/manual/en/function.strtotime.php

5.1.0 Now returns FALSE on failure, instead of -1.

Also a note at the bottom of that page states:

Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

So I think Windows even though it is the 64bit version might be using 32bit integers with php. Did you install 64bit version of php?

phpinfo() should be able to show what version of php is running under the System line.

Jeremy Heslop
Even the 64-bit versions of PHP still use a 32-bit time_t on Windows, so this isn't going to help much - however, an easier test for the question you asked is to have them var_dump(PHP_INT_MAX);
TML
There is a 64-bit version of php here: http://www.fusionxlan.com/PHPx64.php Looked on the main php.net website and I don't think they officially support 64bit php atm.
Jeremy Heslop
+2  A: 

This was allegedly fixed in 2008, as indicated by bug #44209.

[email protected] says,

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/.

Thank you for the report, and for helping us make PHP better.

Jonathan Sampson
Yep, it's fixed there - however, the only "64-bit windows" distribution of PHP (http://www.fusionxlan.com/PHPx64.php) is using a source tree that existed almost a year prior to that fix.
TML
That's the version we are using from fusionxlan. Is there anything we can do to update that version to support 64 bit timestamps?
Jason
+3  A: 

Use the DateTime class as it works in 32bit and 64bit and is built into php5x

http://us.php.net/manual/en/class.datetime.php

<?php

$dateTime = new DateTime("+200 years");


echo $dateTime->format("Y-m-d H:i:s");

?>
ladieu
Even though, on the surface, this will probably seem like bad advice (you'll likely have to rewrite quite a bit of code), it's actually a really good suggestion that I probably should have thought of. Well done, ladieu.
TML
nice..this worked great for me. I will have to update my code which I'm not thrilled about but at least it's core functionality.
Jason
do this: add this function<hr>function adodb_strtotime($str){ $dateTime = new DateTime($str); return $dateTime->format("U");}then use this library: http://phplens.com/phpeverywhere/adodb_date_librarythen this will minimize your rewriting to just addign adodb in front of date functions
ladieu
+1  A: 

To minimize code rewrite:

<?php    
function adodb_strtotime($str) {
   $dateTime = new DateTime($str);
    return $dateTime->format("U");
}
?>

then add this class: http://phplens.com/phpeverywhere/adodb_date_library

then just add adodb_ in front of all your normal date functions. for example mktime will be adodb_mktime

date will be adodb_date

strtotime will be adodb_strtotime... you get the idea

ladieu
A: 

good answer.. yahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhoooooooooooooooooooooooooooooo

aaaa