Here are two scripts that return the time difference between two dates in Oracle:
1.The following script returns the time portion in seperated columns :
SECOUNDS MINUTES HOURS DAYS
38 8 10 2569
SELECT TO_CHAR(DATES.TIME_KEY, 'DD/MM/YYYY:HH24:MI:SS') AS TIME_KEY,
TO_CHAR(SYSDATE, 'DD/MM/YYYY:HH24:MI:SS') AS TODAY,
trunc(86400 * (SYSDATE - DATES.TIME_KEY)) -60 * (trunc((86400 * (SYSDATE - DATES.TIME_KEY) / 60))) AS SECOUNDS,trunc((86400 * (SYSDATE - DATES.TIME_KEY)) / 60) -60 *(trunc(((86400 * (SYSDATE - DATES.TIME_KEY)) / 60) / 60)) AS MINUTES,trunc(((86400 * (SYSDATE - DATES.TIME_KEY)) / 60) / 60) -24 *(trunc((((86400 * (SYSDATE - DATES.TIME_KEY)) / 60) / 60) / 24)) AS HOURS,trunc((((86400 * (SYSDATE - DATES.TIME_KEY)) / 60) / 60) / 24) AS DAYS
FROM DATES.TIME_KEY
2.The following script returns the time portion in hours,minutes and secounds in one column :
HOURS MINUTES SECOUNDS
61 : 22 : 11
SELECT
TO_CHAR(DATES.TIME_KEY.TIME_KEY, 'DD/MM/YYYY:HH24:MI:SS') AS TIME_KEY,
TO_CHAR(SYSDATE, 'DD/MM/YYYY:HH24:MI:SS') AS TODAY,
(sysdate - nvl(DATES.TIME_KEY.TIME_KEY, sysdate)) * 24 as hour_diff,
floor((SYSDATE - DATES.TIME_KEY.TIME_KEY) * 24) ' : '
mod(floor((SYSDATE - DATES.TIME_KEY.TIME_KEY) * 24 * 60), 60)' : '
mod(floor((SYSDATE - DATES.TIME_KEY.TIME_KEY) * 24 * 60), 60)' : '
mod(floor((SYSDATE - DATES.TIME_KEY.TIME_KEY) * 24 * 60 * 60), 60)' ' time_difference
FROM DATES.TIME_KEY
These scripts can become universe objects and are good for call center calculation
No comments:
Post a Comment