-2

谁能解决我的问题。我有带有 time_start 'hour:minute' 和 time_end 'hour:minute' 的 mysql 表,如何获得 time_start 和 time_end 之间的累积持续时间。谢谢,

$sel = $db->query("SELECT * FROM logbook WHERE date = '$date' ");

while($sel_row = mysqli_fetch_array($sel))
{
  $duration = (strtotime($sel_row['time_end'])-strtotime($sel_row['time_start']))/(60*60);        
  $hour = floor($duration);
  $minute = ($duration - $hour)*60;
  echo $hour.":".$minute;
  ? HERE HOW CAN I CUMULATE THE $hour:$minute       
}
4

1 回答 1

0

在计算持续时间的地方进行求和

$duration = 0;
while($sel_row = mysqli_fetch_array($sel))
{
  $duration += (strtotime($sel_row['time_end'])-strtotime($sel_row['time_start']))/(60*60);        
}
$hour = floor($duration);
$minute = ($duration - $hour)*60;
echo $hour.":".$minute;

或者更好的是,让 MySQL 进行计算:

SELECT (SUM(time_end) - SUM(time_start)) / 3600 FROM logbook WHERE date = '$date'; 
于 2012-11-05T06:24:29.573 回答