Reputation: 578
Is there any native function for getting the difference between two timestamps? I want to get minutes difference of two timestamps.
Edit: Sorry but actually I just want the difference of two Unix timestamp.
$date = new DateTime();
$date1_timestamp = $date->getTimestamp();
sleep('120');
$date2_timestamp = $date->getTimestamp();
function get_unix_timestamp_minutes_difference($start, $end) {
/*
Some code for return the difference between two unix timestamps
*/
}
echo get_timestamp_minutes_difference($date1_timestamp, $date2_timestamp);
Upvotes: 0
Views: 2047
Reputation: 149
Try This:
$datetime1 = strtotime("2017-05-16 10:00:00");
$datetime2 = strtotime("2017-05-16 10:45:00");
$interval = abs($datetime2 - $datetime1);
$minutes = round($interval / 60);
echo 'Diff. in minutes is: '.$minutes;
Upvotes: 0
Reputation: 19
You can use Carbon class http://carbon.nesbot.com/docs/ and use his difference API :http://carbon.nesbot.com/docs/#api-difference
Upvotes: 1