Reputation: 2472
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
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