Steve
Steve

Reputation: 1058

PL/SQL time segment calculation

I need to figure how much time passed between 2 times. For example:

(14:00:00 - 13:15:00) * 24 = .75

I need this to later on convert KW to KWh, but that's not the point.

I can not find out how to do this in PL/SQL.

My date/time fields look like this in the DB:

1/23/2010 21:00:00

I would appreciate any suggestions.

Steve

Upvotes: 0

Views: 807

Answers (1)

Ian Carpenter
Ian Carpenter

Reputation: 8626

If you are using 9i above does this give you the expected result?

select extract(hour from numtodsinterval(to_date('14:00:00','HH24:MI:SS') - to_date('13:15:00','HH24:MI:SS'),'DAY'))
||':'|| extract(minute from numtodsinterval(to_date('14:00:00','HH24:MI:SS') - to_date('13:15:00','HH24:MI:SS'),'DAY')) diff
from dual
/

DIFF
------------------

0:45

Extract is detailed here

and numtodsinterval is detailed here

Upvotes: 1

Related Questions