Reputation: 4094
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.
Upvotes: 2
Views: 5593
Reputation: 46425
DATEDIFF :
From the msdn, it returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate. The DATEDIFF()
function returns the time between two dates.
Syntax :
DATEDIFF ( datepart , startdate , enddate )
You should use TIMEDIFF()
or TIMESTAMPDIFF()
function.
Just replace TIMESTAMPDIFF()
function with DATEFDIFF()
Upvotes: 1
Reputation: 115650
DATEDIFF()
returns days of difference.
Use TIMEDIFF()
or convert both timestamps with TO_SECONDS()
) and get their difference:
SELECT TO_SECONDS(log.end_time) - TO_SECONDS(log.start_time) AS seconds
FROM log
WHERE log.log_id = "some crazy UUID"
;
Upvotes: 2
Reputation: 65587
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";
Upvotes: 6
Reputation: 13223
Try this
SELECT TIME_TO_SEC( TIMEDIFF( log.start_time, log.end_time )) AS seconds
FROM log
WHERE log.log_id = "some crazy UUID";
Upvotes: 3
Reputation: 86476
DATEDIFF accept only two parameters and you are passing three parameters here.
How it works and also it returns only the difference b/w dates not including time.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
Upvotes: 2