Mysql – How to get the difference between two datetimes in MYSQL

datediffdatetimemysqltime

I'm trying this

SELECT DATEDIFF(second,log.start_time,log.end_time) 
as seconds 
from log 
where log.log_id = "some crazy UUID";

but I get an error because DATEDIFF() accepts no formatter expr like second.

So I tried,

SELECT second(DATEDIFF(second,log.start_time,log.end_time)) 
as seconds 
from log
where log.log_id = "some crazy UUID";

But that doesn't work for formatting either.

Best Solution

I think you meant to use TIMESTAMPDIFF() instead of DATEDIFF():

SELECT TIMESTAMPDIFF(second,log.start_time,log.end_time) as seconds 
from log 
where log.log_id = "some crazy UUID";