What is the way to get the timespan between two dates in Oracle 9i
Question
Which is the best way in Oracle 9i to get the difference between two dates including the times ? Something like the Timespan function in C#.
Thanks, Chak
Solution
You can express the difference as a numeric number of days, or as an interval data type: http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/expressions9a.htm#1033525
OTHER TIPS
When you subtract two dates you get the difference in days. If you multiply that number by 24 you have the difference in hours. Multiply that number by 60 you have the difference in minutes, etc.
When you do subtraction between dates (type DATE), you get a number that represents the number of days (note this is of a NUMBER(p,s) type, not an INTEGER, as many T-SQL folks get confused in Oracle). Then you can convert that number into seconds by multiplying it by 24*60*60.
n_diff := ABS(date1 - date2) * 24*60*60;