Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting String to int in PHP

Tags:

string

php

int

    $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?

like image 867
TheLettuceMaster Avatar asked Feb 19 '23 05:02

TheLettuceMaster


1 Answers

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

like image 59
Will Sampson Avatar answered Mar 05 '23 03:03

Will Sampson