Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle timestamp difference greater than X hours/days/months

I am trying to write a query to run on Oracle database. The table ActionTable contains actionStartTime and actionEndTime columns. I need to find out which action took longer than 1 hour to complete.

actionStartTime and actionEndTime are of timestamp type

I have a query which gives me the time taken for each action:

select (actionEndTime - actionStartTime) actionDuration from ActionTable

What would be my where clause that would return only actions that took longer than 1 hour to finish?

like image 689
srikanta Avatar asked Jul 07 '11 19:07

srikanta


People also ask

How do I find the difference between two times in Oracle?

To calculate the difference between the timestamps in Oracle, simply subtract the start timestamp from the end timestamp (here: arrival - departure ). The resulting column will be in INTERVAL DAY TO SECOND . The first number you see is the number of whole days that passed from departure to arrival .

Can we use datediff in Oracle?

Use the @DATEDIFF function to calculate the difference between two dates or datetimes, in days or seconds. The difference between the specified dates. Valid values can be: DD , which computes the difference in days.

What is the difference between TIMESTAMP and date in Oracle?

TIMESTAMP is the same as DATE , except it has added fractional seconds precision. The biggest difference: DATE is accurate to the second and doesn't have fractional seconds. TIMESTAMP has fractional seconds.


1 Answers

Subtracting two timestamps returns an interval. So you'd want something like

SELECT (actionEndTime - actionStartTime) actionDuration
  FROM ActionTable
 WHERE actionEndTime - actionStartTime > interval '1' hour
like image 113
Justin Cave Avatar answered Nov 10 '22 00:11

Justin Cave