Praveen Kumar Praveen Kumar - 3 months ago 14
PHP Question

convert timestamp string to timestamp integer php

Here is my php code


Here is output

string(13) "1468821556126" int(2147483647)

Expected output

string(13) "1468821556126" int(1468821556126)

Why this is happening and how to resolve this issue ?


You cannot get a reliable result because your number is too large to be represented as an integer.

echo PHP_INT_MAX; //2147483647 on my system

For a number as large as yours, if you need it in numerical format, cast it to a float instead of an integer

echo floatval('1468821556126'); //1.46882155613E+12

From there, if you're trying to get a date, I assume that this is Javascript time, which is in milliseconds. To convert to a Unix Timestamp, you'll then need to divide it by 1000.