EXTRACT()

<< | FB 2.0 Language Reference | >>

EXTRACT()

Available in: DSQL, ESQL, PSQL

Added in: IB 6

Description

Extracts and returns an element from a DATE, TIME or TIMESTAMP expression. It was already added in InterBase 6, but not documented in the Language Reference at the time.

Result type: SMALLINT or DECIMAL(6,4)

Syntax

 EXTRACT (<part> FROM <datetime>)

 <part> ::= YEAR | MONTH | DAY | WEEKDAY | YEARDAY
             | HOUR | MINUTE | SECOND

 <datetime> ::= An expression of type DATE, TIME or TIMESTAMP

The returned datatype is DECIMAL(6,4) for the SECOND part and SMALLINT for all others. The ranges are shown in the table below.

If you try to extract a part that isn't present in the date/time argument (e.g. SECOND from a DATE or YEAR from a TIME), an error occurs.

Table 11.2. Ranges for EXTRACT results
PartRangeComment
YEAR19999 
MONTH112 
DAY131 
WEEKDAY060 = Sunday
YEARDAY03650 = January 1
HOUR023 
MINUTE059 
SECOND0.000059.999 

See also:
Firebird Null Guide: Internal functions and directives

back to top of page
<< | FB 2.0 Language Reference | >>