score:4

Accepted answer

You can use CASE expression inside the DATEDIFF function:

SELECT
    Diff = 
        DATEDIFF(
            HOUR, 
            timeIn, 
            CASE 
                WHEN timeOut < timeIn THEN DATEADD(DAY, 1, timeOut) 
                ELSE timeOut 
            END
        )
FROM tbl

This will add one day on timeOut if it's less than the timeIn.


More questions

More questions with similar tag