Icon EXTRACT

Extracts the a portion of an interval value.

Syntax
EXTRACT(<ValueToExract> FROM <IntervalExpression>)
EXTRACT(<ValueToExract>, <IntervalExpression>)

<ValueToExtract> =

YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
MSECOND

<IntervalExpression> =

Type of:

INTERVAL YEAR [TO MONTH]
INTERVAL MONTH
INTERVAL DAY [TO HOUR|MINUTE|SECOND|MSECOND]
INTERVAL HOUR [TO MINUTE|SECOND|MSECOND]
INTERVAL MINUTE [TO SECOND|MSECOND]
INTERVAL SECOND [TO MSECOND]
INTERVAL MSECOND

Returns
INTEGER

Usage
The EXTRACT function extracts a designated portion of an interval value and returns it. The following table details which portions can be extracted from which types:

PortionTypes
YEARINTERVAL YEAR
INTERVAL YEAR TO MONTH
MONTHINTERVAL YEAR TO MONTH
INTERVAL MONTH
DAYINTERVAL DAY
INTERVAL DAY TO HOUR
INTERVAL DAY TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
HOURINTERVAL DAY TO HOUR
INTERVAL DAY TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
INTERVAL HOUR
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND
INTERVAL HOUR TO MSECOND
MINUTEINTERVAL DAY TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND
INTERVAL HOUR TO MSECOND
INTERVAL MINUTE
INTERVAL MINUTE TO SECOND
INTERVAL MINUTE TO MSECOND
SECONDINTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
INTERVAL HOUR TO SECOND
INTERVAL HOUR TO MSECOND
INTERVAL MINUTE TO SECOND
INTERVAL MINUTE TO MSECOND
INTERVAL SECOND
INTERVAL SECOND TO MSECOND
MSECONDINTERVAL DAY TO MSECOND
INTERVAL HOUR TO MSECOND
INTERVAL MINUTE TO MSECOND
INTERVAL SECOND TO MSECOND
INTERVAL MSECOND

Examples
SELECT EXTRACT(HOUR FROM (EndTime - StartTime)) AS NumHours
FROM TimeCards

SQL 2003 Standard Deviations
This function deviates from the SQL 2003 standard in the following ways:

DeviationDetails
None
Image