Reputation: 1209
I want to get a difference between two dates in Php in milliseconds, How can I do this? I tried with the following code but not working for me, I am getting the result in seconds, how can I convert to milliseconds? Here is my code.
$expiration_time=$row['time'];
$date = date('Y-m-d H:i:s');
$date1 = strtotime($expiration_time);
$date2 = strtotime($date);
echo $diff = abs($date2 - $date1);
Upvotes: 1
Views: 5537
Reputation: 1702
$milliseconds = strtotime($date) * 1000;
Just multiply it by 1000.
Although I do prefer to use:
$milliseconds = round(microtime(true) * 1000);
Upvotes: 3