Skip to main content

Interval Functions

This section describes functions and operators for examining and manipulating INTERVAL values.

Interval Operators​

The table below shows the available mathematical operators for INTERVAL types.

OperatorDescriptionExampleResult
+addition of an INTERVALINTERVAL 1 HOUR + INTERVAL 5 HOURINTERVAL 6 HOUR
+addition to a DATEDATE '1992-03-22' + INTERVAL 5 DAY1992-03-27
+addition to a TIMESTAMPTIMESTAMP '1992-03-22 01:02:03' + INTERVAL 5 DAY1992-03-27 01:02:03
+addition to a TIMETIME '01:02:03' + INTERVAL 5 HOUR06:02:03
-subtraction of an INTERVALINTERVAL 5 HOUR - INTERVAL 1 HOURINTERVAL 4 HOUR
-subtraction from a DATEDATE '1992-03-27' - INTERVAL 5 DAY1992-03-22
-subtraction from a TIMESTAMPTIMESTAMP '1992-03-27 01:02:03' - INTERVAL 5 DAY1992-03-22 01:02:03
-subtraction from a TIMETIME '06:02:03' - INTERVAL 5 HOUR01:02:03

Interval Functions​

The table below shows the available scalar functions for INTERVAL types.

FunctionDescriptionExampleResult
date_part(part, interval)Get subfield (equivalent to extract)date_part('year', INTERVAL '14 months')1
datepart(part, interval)Alias of date_part. Get subfield (equivalent to extract)datepart('year', INTERVAL '14 months')1
extract(part from interval)Get subfield from a dateextract('month' FROM INTERVAL '14 months')2
to_days(integer)Construct a day intervalto_days(5)INTERVAL 5 DAY
to_hours(integer)Construct a hour intervalto_hours(5)INTERVAL 5 HOUR
to_microseconds(integer)Construct a microsecond intervalto_microseconds(5)INTERVAL 5 MICROSECOND
to_milliseconds(integer)Construct a millisecond intervalto_milliseconds(5)INTERVAL 5 MILLISECOND
to_minutes(integer)Construct a minute intervalto_minutes(5)INTERVAL 5 MINUTE
to_months(integer)Construct a month intervalto_months(5)INTERVAL 5 MONTH
to_seconds(integer)Construct a second intervalto_seconds(5)INTERVAL 5 SECOND
to_years(integer)Construct a year intervalto_years(5)INTERVAL 5 YEAR

Only the documented date parts are defined for intervals.