lakesh lakesh - 2 months ago 15
PHP Question

How to find the difference between two UNIX timestamps in minutes PHP

I am trying to find the difference between the two UNIX timestamps in minutes in php.

I wrote such a code:

$current_time = 1474719107000;
$start_time = 1474716600000;
$difference = $current_time - $start_time;
echo $difference/60;


The difference should be almost 40 mins. But I am getting a value of 41783.333333333. Not sure what's my mistake.

Need some guidance on this.

Answer

Your two timestamps are in milliseconds. You need to further divide them by 1000.

echo $difference/60/1000;