Veljko
Veljko

Reputation: 1808

SQL SELECT Difference between two days greater than 1 day

I have table T1

ID  SCHEDULESTART         SCHEDULEFINISH
1   2018-05-12 14:00:00   2018-05-14 11:00:00
2   2018-05-30 14:00:00   2018-06-01 11:00:00
3   2018-02-28 14:00:00   2018-03-02 11:00:00
4   2018-02-28 14:00:00   2018-03-01 11:00:00
5   2018-05-30 14:00:00   2018-05-31 11:00:00

I want to select all rows where difference in days (it's not important difference in hours) is greater than 1 day. If SCHEDULESTART or SCHEDULEFINISH are on the same day or SCHEDULEFINISH is on next day then these rows should NOT be selected. So the result should return rows with IDs: 1 2 3 because first row have difference in two days, second row (1st June is 2 days after 30th May ) and 3rd row (2nd March is 2 days after 28 February). Is this possible somehow? I know the function DAY but this will return only day number in that one month!!! I must beging my query with

SELECT ID FROM T1 WHERE ... 

Thanks in advance

Upvotes: 0

Views: 2332

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271151

In DB2, this should work:

select t1.*
from t1
where date(schedulestart) < date(schedulefinish) - 1 day;

Upvotes: 1

Related Questions