Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateInternal functions → EXTRACT()
Firebird Home Firebird Home Prev: COALESCE()Firebird Documentation IndexUp: Internal functionsNext: 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

Part Range Comment
YEAR 1–9999  
MONTH 1–12  
DAY 1–31  
WEEKDAY 0–6 0 = Sunday
YEARDAY 0–365 0 = January 1
HOUR 0–23  
MINUTE 0–59  
SECOND 0.0000–59.999  


Prev: COALESCE()Firebird Documentation IndexUp: Internal functionsNext: GEN_ID()
Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateInternal functions → EXTRACT()