-3

I have 2 dates in mysql:
2018-07-13 13:00:00 - data
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";

Now it returns: 27.016666666667

How to change it to: 27:01 in table?

Qirel
  • 25,449
  • 7
  • 45
  • 62

1 Answers1

1

You can simply use DateTime->diff method to get the interval between those 2 dates:

$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);
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50