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
orTIMESTAMP
(subtrahend). - givenTime2: The second
DATE
orTIMESTAMP
(minuend).
Examples
TIMESTAMPDIFF exampleSELECT TIMESTAMPDIFF(MONTH, DATE '2021-02-01', DATE '2021-05-01');
-- 3
SELECT TIMESTAMPDIFF(DAY, TIMESTAMP '2003-02-01 11:43:22', TIMESTAMP '2005-04-09 12:05:55');
-- 798