Another great resource I found for finding the difference between two dates:
http://asktom.oracle.com/t
Main Topics
Browse All TopicsUsing Oracle 8i
I have a query that returns 3 columns col1, col2, Time_Diff from myTable as shown below. Time_Diff is the difference between a date column (col3) in myTable and SysDate.
Select A.col1, A.col2, B.Time_Diff
from myTable A, (Select (sysdate - col3 ) As "Time_Diff" from Dual) B
Also, I would like Time_Diff to be returned in the format 01:15, meaning the time difference is 1 hour, 15 minutes.
Please help me as I have very limited knowledge of how to write oracle queries.
Thanks
San
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Another great resource I found for finding the difference between two dates:
http://asktom.oracle.com/t
Thank you Anokun7.
I am trying to get the result in the format Hr:Minute,
So, this is what I tried
select A.col1, A.col2, B.Time_Diff
From myTable A,
( Round((select SYSDATE - T.motk_time_issued from Dual) * 24 * 60) / 60) || ':' || Mod((select SYSDATE - T.motk_time_issued from Dual) * 24 * 60) /60) ) B
I don't know what I am doing. As you can see from the above sql, I am trying to concatenate the rounded hour with colon then with the mod. I'm trying to get the time difference to display like so 01:15 meaning 1 hour and 15 minute difference.
Please help and thanks.
San
here is an example:
SQL> select * from t;
END_DATE START_DAT
--------- ---------
28-APR-07 28-APR-07
SQL> select sysdate - end_date from t;
SYSDATE-END_DATE
----------------
.133576389
SQL> select trunc( mod( (sysdate - end_date)*24, 24 ) )||':'||trunc( mod( (sysdate - end_date)*24*60, 60 ) ) from t;
TRUNC(MOD((SYSDATE-END_DAT
--------------------------
3:15
SQL>
Hello,
Two improvements on anokun7 suggestion:
1. to get 03:15 instead of 3:15 (and further if the return value was 3hours and 5 minutes anokun7 query would return 3:5 instead of 03:05) you should modify format the return statement as the following:
SELECT LPAD (TO_CHAR (TRUNC (MOD ((SYSDATE - end_date) * 24, 24))), 2, '0')
|| ':'
|| LPAD (TO_CHAR (TRUNC (MOD ((SYSDATE - end_date) * 24 * 60, 60))), 2, '0')
FROM t;
2. what anokun7 suggested is correct, if you know that the difference between end_date and sysdate is less than one day, of if you only want the time difference. If not you should cater for the date part as well. You can do that by adding TRUNC(SYSDATE - end_date)||' Days, ' at the begining of the expression:
SELECT TRUNC(SYSDATE - end_date)||' Days, '|| /* This is the days diff */
LPAD (TO_CHAR (TRUNC (MOD ((SYSDATE - end_date) * 24, 24))), 2, '0')
|| ':'
|| LPAD (TO_CHAR (TRUNC (MOD ((SYSDATE - end_date) * 24 * 60, 60))), 2, '0') Time_Diff
FROM t;
If you just want the time of day differential, then
select lpad(trunc(((sys_date - trunc(sys_date)) - (col3 - trunc(col3))) * 24),2,0)
||':'||lpad(round(mod(((sy
from datetbl;
If you want the total hours and minutes difference between the two dates, then
select lpad(trunc((sys_date - col3) * 24),2,0)
||':'||lpad(round(mod((sys
from datetbl;
Here are the test examples -
SQL> select to_char(col3,'dd-mon-yy hh24:mi')
2 ,to_char(sys_date,'dd-mon-
3 from datetbl;
TO_CHAR(COL3,'DD-MON- TO_CHAR(SYS_DATE,'DD-
--------------------- ---------------------
28-apr-07 12:30 29-apr-07 13:45
28-apr-07 12:38 29-apr-07 13:45
SQL> select lpad(trunc(((sys_date - trunc(sys_date)) - (col3 - trunc(col3))) * 24),2,0)
2 ||':'||lpad(round(mod(((sy
3 from datetbl;
TIME_DIFF
-------------
01:15
01:07
SQL> select lpad(trunc((sys_date - col3) * 24),2,0)
2 ||':'||lpad(round(mod((sys
3 from datetbl;
TIME_DIFF
-------------
25:15
25:07
Business Accounts
Answer for Membership
by: anokun7Posted on 2007-04-28 at 14:25:05ID: 18995370
select (sysdate - col3) * 24 * 60 * 60 from t;
ls/asktom/ f? p=100:11 :0::::P11_ QUESTION_I D:96012348 060
sysdate - col3 gives diff in days (eg: 1.2323 days)
multiply by 24 = hours, another 60 = minutes, another 60 = seconds
Source: http://asktom.oracle.com/p