DateDiff in PL/SQL

1.5k views Asked by At

How to find difference between 2 timestamps in seconds?

Is there any system function or I should manually calculate some second like this

SELECT t1_id,
EXTRACT(Day FROM(mod_date_time – create_date_time) DAY TO SECOND) as Day,
EXTRACT(HOUR FROM(mod_date_time – create_date_time) DAY TO SECOND) as Hour,
EXTRACT(Minute FROM(mod_date_time – create_date_time) DAY TO SECOND) as Minute,
EXTRACT(SECOND FROM(mod_date_time – create_date_time) DAY TO SECOND) as second
FROM t1;
1

There are 1 answers

2
Hawk On

In Oracle, dates are just numbers. Each day is 1 integer. Finding the seconds difference can be done as follows:

SELECT (mod_date_time - create_date_time) * 24 * 60 * 60 as "seconds_diff"
FROM t1