通过跳过某些小时来计算timediff

时间:2014-09-17 06:33:44

标签: mysql date

投诉创建日期:2014-09-16T18:41:42.000Z

投诉截止日期:2014-09-17T10:41:42.000Z

如果投诉在创建日期后第二天关闭,则会跳过(7Pm to 10 Am time)

关闭时间:1小时(Skip Time 7PM to 10 AM)

1 个答案:

答案 0 :(得分:0)

此选择查询是用SQL Server编写的。我不知道MySql的语法。您可以从此查询中获取LOGIC。试试这个,

select * 
    ,Datediff(dd,CreatedDate,ClosedDate) as D
    ,Datediff(hh,CreatedDate,ClosedDate) as H
    ,Case When Datediff(dd,CreatedDate,ClosedDate) > 0
            Then Datediff(hh,CreatedDate,ClosedDate) - (15 * Datediff(dd,CreatedDate,ClosedDate))
            else Datediff(hh,CreatedDate,ClosedDate)
    End [Time for closure]
from Request