4
    $date = "1346706576967";  // miliseconds
    $newDate = (int) $date;
    echo $newDate;

I am getting "2147483647" as $newDate.

I simply want to convert the variable from String 1346706576967 to int 1346706576967 - how is this possible?

1
  • I have Godaddy hosting, how is this possible to change? Commented Sep 7, 2012 at 17:14

4 Answers 4

5

2147483647 is the largest value an integer can hold unfortunately. You could use a float here instead as a float can accurately hold integer values up to 10000000000000

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

1 Comment

Building on Will's answer, just use ` $date = "1346706576967"; // miliseconds $newDate = floatval($date); echo $newDate;`
2

Because that is maximum size an integer in PHP can have. You'll need a PHP library specific made for dealing with bigger integers like BCMath or GMP or just convert it to a float.

Comments

1

possible conversions,

$input => 1346706576967
(integer)$input => 2147483647
intval($input) => 2147483647
$input*1 => 1346706576967
settype($input, "integer") => 1346706576967

http://phpconvert.com/online/

Comments

0

You can use implicit conversion to convert it correctly:

$date = "1346706576967";  // miliseconds
$newDate = 0+$date; // float(1346706576967)
$newDate = (int) $date; // int(2147483647)

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.