时间计算Timeformat减去

时间:2017-11-01 12:35:13

标签: php mysql time

我有一个代码,显示sombody在特定日期工作了多少小时。

SELECT ur.id,us.username, '' as callback_del,datum, ur.description,
        DATE_FORMAT(ur.time_from, '%H:%i') as nosearch_tijdvan,
        DATE_FORMAT(ur.time_till, '%H:%i') as nosearch_tijdtot,
        DATE_FORMAT(break, '%H:%i') as nosearch_pauze,
        TIME_FORMAT(TIMEDIFF(time_from,time_till), '%H:%i') as nosearch_diff,   
        TIME_FORMAT(TIMEDIFF(time_from,time_till)  - break, '%H:%i') AS nosearch_totaal
        FROM " . uren . " AS ur
        JOIN " . project . " AS pr ON pr.project_id = ur.project_id
        JOIN " . user . " AS us ON us.userid = ur.userid

例如

time_from = 07:00:00

time_till = 16:00:00

break = 01:00:00小时

  

输出= 08:00:00工作时间

但如果休息时间= 00:30:00

  

输出= NULL

sombody是否有解决问题的方法

由于

1 个答案:

答案 0 :(得分:1)

尝试

TIMEDIFF(TIMEDIFF(time_from,time_till), break)

而不是

(TIMEDIFF(time_from,time_till)  - break)