如何计算现在和任何日期之间的总小时数,但要排除工作日?
我正在尝试这种方式:
select id, creationTime,
time_format(timediff(now(), creationTime), '%H:%m:%s') AS totalspenttime
from tblrezgo where DAYOFWEEK(creationTime) NOT IN (1,7)
此查询应删除星期六和星期日的计算,但似乎也包括那两天。
通过运行查询:
select id, creationTime, DAYOFWEEK(creationTime) FROM tblrezgo
输出是:
+-------------+---------------------+------------+
| ID | creationTime | DAYOFWEEK |
+-------------+---------------------+------------+
| 1 | 2015-10-23 17:12:05 | 6 |
+-------------+---------------------+------------+
| 2 | 2015-10-24 10:23:11 | 7 |
+-------------+---------------------+------------+
| 3 | 2015-10-24 11:51:04 | 7 |
+-------------+---------------------+------------+
| 4 | 2015-10-26 14:30:28 | 2 |
+-------------+---------------------+------------+
| 5 | 2015-10-26 08:24:59 | 2 |
+-------------+---------------------+------------+
| 6 | 2015-10-26 17:29:03 | 2 |
+-------------+---------------------+------------+
| 7 | 2015-10-27 08:16:45 | 3 |
+-------------+---------------------+------------+
如果我运行我的查询,那么ID = 1的totalspenttime大约是86小时,这是不正确的。我已经检查了,现在应该是大约41个小时(如果我们在周末执行两天)。