Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 求平均时间_Php_Mysql - Fatal编程技术网

Php 求平均时间

Php 求平均时间,php,mysql,Php,Mysql,我需要找出平均时间。学生的考试花了很多时间。我有开始时间和结束时间。和总计数。 但它在网上给出了错误 $start_dateav = new DateTime($start_time_av); 致命错误:未捕获的异常“exception”带有消息 'DateTime::_构造():无法分析时间字符串(2015年12月19日) 01:55:13 pm)在位置0(1):意外字符“in” E:\xampp\htdocs\mock\report.php:117堆栈跟踪:#0 E:\xampp\htdo

我需要找出平均时间。学生的考试花了很多时间。我有开始时间和结束时间。和总计数。
但它在网上给出了错误

$start_dateav = new DateTime($start_time_av);
致命错误:未捕获的异常“exception”带有消息 'DateTime::_构造():无法分析时间字符串(2015年12月19日) 01:55:13 pm)在位置0(1):意外字符“in” E:\xampp\htdocs\mock\report.php:117堆栈跟踪:#0 E:\xampp\htdocs\mock\report.php(117): DateTime->uu构造('19/12/2015 01:5…')#1{main}被抛出 第117行的E:\xampp\htdocs\mock\report.php

在同一个php页面上,我使用相同的方法获取时间。工作正常

$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.'';

解决了我使用日期Y-m-d而不是d/m/Y

为什么不在sql中这样做?
$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.'';