I don’t know if I understand this right, but I think this is what you want
select CAST( '2018-01-01 17:00:01' AS DATETIME ) AS data_um,
CAST( '2018-01-02 10:01:02' AS DATETIME ) AS data_dois,
DATEDIFF( SECOND, CAST( '2018-01-01 17:00:01' AS DATETIME ),CAST( '2018-01-02 10:01:02' AS DATETIME ) ) / 60/ 60/ 24 AS difer_dias,
DATEDIFF( SECOND, CAST( '2018-01-01 17:00:01' AS DATETIME ),CAST( '2018-01-02 10:01:02' AS DATETIME ) ) / 60/ 60 AS difer_horas,
DATEDIFF( SECOND, CAST( '2018-01-01 17:00:01' AS DATETIME ),CAST( '2018-01-02 10:01:02' AS DATETIME ) ) / 60% 60 AS difer_minutos,
DATEDIFF( SECOND, CAST( '2018-01-01 17:00:01' AS DATETIME ),CAST( '2018-01-02 10:01:02' AS DATETIME ) ) % 60 AS difer_segundos
It will show the amount of seconds, minutes, hours and days in a way that can be used in full, for example:
Passed by 0
days, 17
hours, 1
minute and 1
second since the last check.
You should include a sample code of how you are performing queries to get this result.
– Leandro Angelo
Possible duplicate of Difference between two dates in days, hours, minutes and seconds
– Marconi