我在mysql中有2个日期:
2018-07-13 13:00:00-数据
2018-07-14 16:01:00-Godzina
$timestamp1 = strtotime($data['data']);<br>
$timestamp2 = strtotime($data['godzina']);<br>
$time_difference = $timestamp2 - $timestamp1;
$time_total = ($time_difference/3600);
echo "td".$time_total."/td";
现在它返回:27.016666666667
如何将其更改为:表中的27:01
?
答案 0 :(得分:1)
您可以简单地使用DateTime->diff
方法来获取这两个日期之间的间隔:
$date1 = '2018-07-13 13:00:00';
$date2 = '2018-07-14 16:01:00';
$interval = (new DateTime($date2))->diff(new DateTime($date1));
$totalHours = $interval->days * 24 + $interval->h;
echo sprintf("%02d", $totalHours) . ':' . sprintf("%02d", $interval->i);