0

Short story, here's my code:

var_dump($recentGame->createDate);
var_dump((int) $recentGame->createDate);

Is producing the following output:

float 1416772859827
int -566347853

Why is the output of the typecasted output not this:

int 1416772859827
5
  • 1
    Look at the limits for integers with 32-bit PHP Commented Nov 23, 2014 at 22:08
  • 1
    The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807. php.net/manual/en/function.intval.php Commented Nov 23, 2014 at 22:08
  • So what does that createDate represent as an integer? It isn't a standard unix timestamp is it? Commented Nov 23, 2014 at 22:10
  • It's an epoch time value, I need to create a dateTime object from it. Commented Nov 23, 2014 at 22:17
  • 1
    you have milisecounds so: $seconds = $recentGame->createDate / 1000; echo date("d-m-Y", $seconds); Commented Nov 23, 2014 at 22:24

1 Answer 1

1

Quoting from the PHP docs:

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except for Windows, which is always 32 bit. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.