On this page

    Categories: Date/Time

    TIMESTAMPDIFF

    Return the amount of time between two date or timestamp values

    Syntax

    TIMESTAMPDIFF(unit symbol, giventime1 date or timestamp, givenTime2 date or timestamp) → INTEGER

    • unit: The unit of the interval. Must be one of the following: YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND.
    • giventime1: The first date or timestamp (subtrahend)
    • givenTime2: The second date or timestamp (minuend)

    Examples

    TIMESTAMPDIFF example
    SELECT timestampdiff(month, date '2021-02-01', date '2021-05-01');
    -- 3
    
    TIMESTAMPDIFF example
    SELECT timestampdiff(day, timestamp '2003-02-01 11:43:22', timestamp '2005-04-09 12:05:55');
    -- 798