gpt4 book ai didi

php - TIMEDIFF 函数不起作用

转载 作者:行者123 更新时间:2023-11-29 20:16:55 27 4
gpt4 key购买 nike

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);
?>

最佳答案

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

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

关于php - TIMEDIFF 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39704185/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com