4

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

Jason
  • 1,496
  • 4
  • 29
  • 41

5 Answers5

3

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
  • 127
  • 5
  • 17
  • 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 Jan 04 '10 at 20:37
  • 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 Jan 04 '10 at 20:47
  • do this: add this function
    function adodb_strtotime($str) { $dateTime = new DateTime($str); return $dateTime->format("U"); } then use this library: http://phplens.com/phpeverywhere/adodb_date_library then this will minimize your rewriting to just addign adodb in front of date functions
    – ladieu Jan 04 '10 at 20:50
2

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

derick@php.net 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.

Sampson
  • 265,109
  • 74
  • 539
  • 565
  • 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 Jan 04 '10 at 19:52
  • 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 Jan 04 '10 at 19:57
1

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

TML
  • 12,813
  • 3
  • 38
  • 45
  • The OP said "...so upgraded our server to **Windows Server 2003 64-bit** version..." – Sampson Jan 04 '10 at 19:38
  • 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 Jan 04 '10 at 19:39
  • This is the version of php we downloaded and installed. http://www.fusionxlan.com/PHPx64.php It's running on 64bit Windows Server 2003 on IIS6.0. Any options for us to get this working? – Jason Jan 04 '10 at 19:56
  • Just one: Compile your own 64-bit version of PHP. – TML Jan 04 '10 at 20:13
1

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
  • 127
  • 5
  • 17
0

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
  • 568
  • 3
  • 8
  • 1
    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 Jan 04 '10 at 19:44
  • 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 Jan 04 '10 at 19:44