Timothy Clotworthy
Timothy Clotworthy

Reputation: 2472

Oracle SQL - How to determine if the difference between two dates is less than one minute

I have a need to determine in SQL whether the difference between two dates is less that 60 seconds. So I want in pseudo SQL:

IF DATE1 - DATE2 < 60 seconds THEN
    -- do something
END IF;

The problem I am facing is that date differences are not expressed in number but in date formats not easily evaluated against a value expressed in numbers. How can I make this evaluation in SQL?

Any help greatly appreciated!

Upvotes: 1

Views: 457

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269493

You can do:

where abs(date1 - date2) < 1 / (24 * 60)

or:

where date1 > date2 - interval '60' second and
      date1 < date2 + interval '60' second

Upvotes: 4

Related Questions