TIMEDIFF FUNCTION不起作用

时间:2016-09-26 13:26:53

标签: php mysql

Query Ouput

从输出中,您可以看到我可以选择MIN(TIME(Time))但是当我在TIMEDIFF FUNCTION中使用它时,它会将MIN(TIME(Time))读为0并得到-07的结果: 00:00。我希望得到MIN(TIME(Time))和07:00:00的差异,以确定员工迟到的小时数。对于如何解决这个问题,有任何的建议吗?所有回复都非常感谢。抱歉英文不好。

以下是代码:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
 border: 1px solid black;
}
</style>
</head>
<body>

<?php
$con=mysqli_connect("localhost","root","","september-system");


// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT User_ID, MIN(TIME(Time)) as time, DATE(Time) as day, TIMEDIFF('MIN(TIME(Time))', '07:00:00')as tdiff  FROM records GROUP BY User_ID, day ORDER BY User_ID, day;";



if (mysqli_multi_query($con,$sql))
{
do
{
// Store first result set
if ($result=mysqli_store_result($con)) {
  echo "<table><tr><th>USER ID</th><th>TIME</th><th>DATE</th><th>ABSENCES</th></tr>";
 // output data of each row
  while ($row=mysqli_fetch_row($result))
    {
    //echo var_dump($row);
    echo "<tr><td>" . $row[0]. "</td><td>" . $row[1]. "</td><td>" . $row[2]. "</td><td>" . $row[3]. "</td></tr>";
    }
  // Free result set
  mysqli_free_result($result);
  }
}
while(mysqli_more_results($con) && mysqli_next_result($con));
}

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:0)

我认为最好从第一个参数中删除单引号 让我试试,我不确定

 TIMEDIFF(MIN(TIME(Time)), '07:00:00')as tdiff