php - Find Average Time -


i need find average time. of students exam taken time. have start time , end time. , total count.
gives error on line.

$start_dateav = new datetime($start_time_av); 

fatal error: uncaught exception 'exception' message 'datetime::__construct(): failed parse time string (19/12/2015 01:55:13 pm) @ 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 * user_test 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); 

on same php page using same method time. working fine.

$sqlm="select * user_test test_id = '$test_id' order 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.''; 

solved use date y-m-d instead of d/m/y


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -