srikanta
srikanta

Reputation: 2999

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?

Upvotes: 7

Views: 10369

Answers (1)

Justin Cave
Justin Cave

Reputation: 231651

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

SELECT (actionEndTime - actionStartTime) actionDuration
  FROM ActionTable
 WHERE actionEndTime - actionStartTime > interval '1' hour

Upvotes: 15

Related Questions