gpt4 book ai didi

mysql - 无法计算正确的总小时数?

转载 作者:行者123 更新时间:2023-11-29 01:53:40 24 4
gpt4 key购买 nike

我有以下字段

Date        InTime    OutTime   Status
2016-01-04 10:19:00 05:10:00 Out

我试过下面的查询

SELECT sum(time_to_sec(timediff(CONCAT(`TodayDate`,' ',`OutTime`),CONCAT(`TodayDate`,' ',`InTime`)))/ 3600) as total FROM `wp_ag_punch` where UserId=$userid and TodayDate='$today'

但它给出了 -5.15 小时。

请帮我解决一下

最佳答案

您使用的是错误的系统架构,而不是为日期和时间使用两个文件,只使用一个适用于所有情况的文件请使用以下结构

DatetimeIn (timestamp)  DatetimeOut (timestamp)  Status
1451912118 1451912140 Out

现在直接做

Select DatetimeIn - DatetimeOut as output

这将在几秒钟内为您提供输出

output
------
22

关于mysql - 无法计算正确的总小时数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34591274/

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