calculating call duration
i am wo开发者_开发问答rking for telecom,i need to calculate call duration of a call.the issue is we have world time 24hrs(00:00:00 - 23:59:59)for example, now the call starts at 22:31:40 and ends at 00:22:56 now i need to calculate the duration of this call. can i know the logic to calculate it
Thanks In advance
There is no DB2 built-in function to do this. However, the DB2 DATE documentation includes the source for a user-defined function which employs DAYS() and MIDNIGHT_SECONDS() to achieve the required result.
CREATE FUNCTION secondsdiff(t1 TIMESTAMP, t2 TIMESTAMP)
RETURNS INT
RETURN (
(DAYS(t1) - DAYS(t2)) * 86400 +
(MIDNIGHT_SECONDS(t1) - MIDNIGHT_SECONDS(t2))
)
@
Add 24 hours to the second time and subtract from the first. If the result is greater than 24 hours, take the 24 back out. This obviously doesn't handle calls that ARE over 24 hours, but we'll assume they arent.
... or use some DB2 function I'm unaware of.
精彩评论