TIMESTAMPDIFF
Returns the time span between two TIMESTAMP or TIMESTAMPTZ values, in the intervals specified.
	Returns the time span between two TIMESTAMP or TIMESTAMPTZ values, in the intervals specified. TIMESTAMPDIFF excludes the start date in its calculation.
Behavior type
Syntax
TIMESTAMPDIFF ( datepart, start, end );
Parameters
- datepart
- Specifies the type of date or time intervals that TIMESTAMPDIFFreturns. Ifdatepartis an expression, it must be enclosed in parentheses:TIMESTAMPDIFF((expression), start, end );datepartmust evaluate to one of the following string literals, either quoted or unquoted:- 
year|yy|yyyy
- 
quarter|qq|q
- 
month|mm|m
- 
day|dayofyear|dd|d|dy|y
- 
week|wk|ww
- 
hour|hh
- 
minute|mi|n
- 
second|ss|s
- 
millisecond|ms
- 
microsecond|mcs|us
 
- 
- start- ,- end
- Specify the start and end dates, where startandendevaluate to one of the following data types:- TIMESTAMP/TIMESTAMPTZ
- 
TIMESTAMPTZ
 If end<start,TIMESTAMPDIFFreturns a negative value.
Date part intervals
TIMESTAMPDIFF uses the datepart argument to calculate the number of intervals between two dates, rather than the actual amount of time between them. For detailed information, see 
DATEDIFF.
Examples
=> SELECT TIMESTAMPDIFF (YEAR,'1-1-2006 12:34:00', '1-1-2008 12:34:00');
 timestampdiff
---------------
             2
(1 row)
See also
DATEDIFF