2

Here is my php code

var_dump($args['startdate']); 
var_dump((int)$args['startdate']);die(); 

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 ?

Praveen Kumar
  • 2,408
  • 1
  • 12
  • 20

3 Answers3

2

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.

BeetleJuice
  • 39,516
  • 19
  • 105
  • 165
1

You're probably using a 32bit system. The number you're seeing is the maximum size of an int on a 32 bit machine. Use float or change to a 64bit machine.

Ref: PHP Integer

adarshdec23
  • 231
  • 2
  • 9
1

It's happening because your $args['startdate'] is in miliseconds, you need to divide it by 1000

lulco
  • 524
  • 2
  • 11
  • 1
    If `$args['startdate']` is a timestamp then this is the only correct answer. `echo(date("Y-m-d H:i:s e", 1468821556126/1000));` prints `2016-07-18 08:59:16 Europe/Bucharest`. – axiac Jul 23 '16 at 06:47
  • @axiac This is probably what the op is looking for. – adarshdec23 Jul 23 '16 at 06:49