私は平均時間を見つける必要があります。学生試験の時間を取った。私は開始時間と終了時間を持っています。総カウント
しかし、その行にエラーが発生します。私は時間を取得するために、同じ方法を使用しています同じPHPページの平均時間を見つける
$start_dateav = new DateTime($start_time_av);
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (19/12/2015 01:55:13 pm) at position 0 (1): Unexpected character' in E:\xampp\htdocs\mock\report.php:117 Stack trace: #0 E:\xampp\htdocs\mock\report.php(117): DateTime->__construct('19/12/2015 01:5...') #1 {main} thrown in E:\xampp\htdocs\mock\report.php on line 117
function average_time($total, $count, $rounding = 0) {
$total = explode(":", strval($total));
if (count($total) !== 3) return false;
$sum = $total[0]*60*60 + $total[1]*60 + $total[2];
$average = $sum/(float)$count;
$hours = floor($average/3600);
$minutes = floor(fmod($average,3600)/60);
$seconds = number_format(fmod(fmod($average,3600),60),(int)$rounding);
return $hours.":".$minutes.":".$seconds;
}
$sqlav="select * from user_test where test_id = '$test_id'";
$resultav=mysqli_query($con,$sqlav);
$takentimeavH = "0";
$takentimeavM = "0";
$takentimeavS = "0";
$totaltst = "3237";
while ($totaltstav=mysqli_fetch_array($resultav)) {
$start_time_av=date('d/m/Y h:i:s a',strtotime($totaltstav['start_time']));
$end_time_av=date('d/m/Y h:i:s a',strtotime($totaltstav['end_time']));
$start_dateav = new DateTime($start_time_av);
$since_startav = $start_dateav->diff(new DateTime($end_time_av));
$takentimeavH += $since_startav->h;
$takentimeavM += $since_startav->i;
$takentimeavS += $since_startav->s;
}
$tataltime = $takentimeavH.':'.$takentimeavM.':'.$takentimeavS;
echo average_time($tataltime, $totaltst);
。そのうまく動作します。
$sqlm="select * from user_test where test_id = '$test_id' order by mark desc limit 1";
$resultm=mysqli_query($con,$sqlm);
$totaltstm=mysqli_fetch_array($resultm);
$maxmarkss=$totaltstm['mark'];
$start_time_toppr=date('d/m/Y h:i:s a',strtotime($totaltstm['start_time']));
$end_time_toppr=date('d/m/Y h:i:s a',strtotime($totaltstm['end_time']));
$start_datetppr = new DateTime($start_time_toppr);
$since_starttppr = $start_datetppr->diff(new DateTime($end_time_toppr));
$takentimetppr = $since_starttppr->h.':'.$since_starttppr->i.':'.$since_starttppr->s.'';
を使用して解決しますか? – Strawberry