为了账号安全,请及时绑定邮箱和手机立即绑定

将时间值加在一起形成总计

将时间值加在一起形成总计

PHP
呼如林 2021-11-05 10:31:37
我有下面的代码,我希望总数是 12:37:47,但我得到的是 12 的整数。这些是结果:类别 1 - 06:02:06类别 2 - 06:35:41总计 - 12我怎样才能得到 12:37:47 的总结果?$sql    = "SELECT hesk_categories.name, COALESCE(NULLIF(SEC_TO_TIME(SUM(TIME_TO_SEC(TimeSpent))),0),'00:00:00') AS TimeSpent from hesk_categories left Join hesk_tickets on hesk_categories.id = hesk_tickets.category left join TimeSpent on hesk_tickets.id = TimeSpent.ID and (DateCreated between  DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() ) where hesk_categories.name <> 'Feature Request' group by hesk_categories.name";$query  = mysqli_query($con, $sql);while ($row = mysqli_fetch_array($query)){    $TimeSpent = $row['TimeSpent'];    $TimeSpent = $TimeSpent + $TimeSpent;    $message.="<tr>";    $message.="<td>" . $row['name'] . "</td>";    $message.="<td>" . $row['TimeSpent'] . "</td>";    $message.="<tr>";}$message.="<tr>";$message.="<td>Total</td>";    if ($TimeSpent >= '10:00:00')    {        $message.="<td><b><font color='red'>" . $TimeSpent . " (Support Hours have exceeded 10 hours for the month.)</font></b></td>";    }    else    {        $message.="<td>" . $TimeSpent . "</td>";    }$message.="</tr>";$message.="</table><br>";
查看完整描述

1 回答

?
慕仙森

TA贡献1827条经验 获得超7个赞

我将此添加到查询中:


SUM(TIME_TO_SEC(TimeSpent)) as TimeSpentSeconds

这对于 if 语句:


if ($TimeSpentSeconds >= 36000)

{

    $TimeSpentSeconds = $TimeSpentSeconds / 3600;

    $message.="<td><b><font color='red'>" . number_format((float)$TimeSpentSeconds, 2, '.', '') . " hrs (Support Hours have exceeded 10 hours for the month.)</font></b></td>";

}

else

{

    $TimeSpentSeconds = $TimeSpentSeconds / 3600;

    $message.="<td>" . $number_format((float)$TimeSpentSeconds, 2, '.', '') . " hrs</td>";

}

做这份工作。


查看完整回答
反对 回复 2021-11-05
  • 1 回答
  • 0 关注
  • 121 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信