EXTRACT()

<< COALESCE() | FB 2.0 Language Reference | GEN_ID() >>

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
YEAR1–9999 
MONTH1–12 
DAY1–31 
WEEKDAY0–60 = Sunday
YEARDAY0–3650 = January 1
HOUR0–23 
MINUTE0–59 
SECOND0.0000–59.999 

See also:
Firebird Null Guide: Internal functions and directives

back to top of page
<< COALESCE() | FB 2.0 Language Reference | GEN_ID() >>