Search code examples
mysqldatetimeintervalsdatediff

SELECT difference in 2 datetime columns WHERE interval


I can't find a solution to this anywhere. All I want to do is subtract datetimecolumn1 from datetime column2, and only select those records where that interval > 1 day. I know this sounds simple, and probably is, but none of the datediff/interval WHERE's I've come up with have worked.


Solution

  • You can use DATEDIFF.

    SELECT *
        , DATEDIFF(datetimecolumn1, datetimecolumn2)
    FROM youtable
    WHERE DATEDIFF(datetimecolumn1, datetimecolumn2) > 1;