Reputation: 545
I want to calculate difference between two dates (using SQL Request) with this format "YYYY-MM-DD HH:mm:ss",the result should be in hours/minutes.
example: "2011-08-02 18:00:00" - "2011-08-03 09:01:00" = 15h and 1 min
1/I haven't found a function that calculate what I want ,just found TIMEDIFF() and DATEDIFF()
2/Also my request don't work because the subquery return more than one row ,I have tried to calculate with datediff to only test the request
select sum(DATEDIFF((select changegroup.CREATED
from changegroup,changeitem
where changegroup.id=changeitem.groupid
and oldString='Closed'
and changegroup.issueid=10301),
(select changegroup.CREATED
where changegroup.id=changeitem.groupid
and newString='Closed'
and changegroup.issueid=10301))) as somme
from changegroup,changeitem;
How can I calculate the difference between two dates and how can I fix my sql request?
thank you
Upvotes: 0
Views: 1751
Reputation: 25844
SELECT Time_format(Timediff('2011-08-03 09:01:00', '2011-08-02 18:00:00'),
'%Hh and %i min')
Upvotes: 2