Reputation: 91
I am writing a query that is selecting two times and calculating the difference between these, where one is the start and the other is the finish to find out the duration. However both are set to TIME types in mysql. How can i format the time instead of showing HH:MM:SS to '[OPTIONAL H]H':MM hrs'
Do i use the extract function? I presume i have to wrap the TIMEDIFF around something else?
my sql code is as follows:
SELECT operator_no, log_in_time, TIMEDIFF(log_in_time,log_out_time) AS Duration
many thanks
Upvotes: 0
Views: 74
Reputation: 91
would this not work too?
SELECT operator_no, log_in_time, CONCAT(EXTRACT(HOUR_MINUTE FROM TIMEDIFF (log_in_time,end_time)) + 'hrs' ) AS Duration
Upvotes: 0
Reputation: 35531
Yes, wrap it in TIME_FORMAT()
:
SELECT operator_no, log_in_time,
TIME_FORMAT(
TIMEDIFF(log_in_time, log_out_time),
'%H:%i hrs'
) AS Duration
Upvotes: 2