8.4.3. EXTRACT()
Available in
DSQL, ESQL, PSQL
Syntax
EXTRACT (<part> FROM <datetime>)
<part> ::=
YEAR | MONTH | WEEK
| DAY | WEEKDAY | YEARDAY
| HOUR | MINUTE | SECOND | MILLISECOND
<datetime> ::= a DATE, TIME or TIMESTAMP expression
Parameter | Description |
---|---|
part | Date/time unit |
datetime | An expression of the |
Result type
SMALLINT
or NUMERIC
Description
Extracts and returns an element from a DATE
, TIME
or TIMESTAMP
expression. This function was already added in InterBase 6, but not documented in the Language Reference at the time.
Returned Data Types and Ranges
The returned data types and possible 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.
Part | Type | Range | Comment |
---|---|---|---|
|
| 1-9999 |
|
|
| 1-12 |
|
|
| 1-53 |
|
|
| 1-31 |
|
|
| 0-6 | 0 = Sunday |
|
| 0-365 | 0 = January 1 |
|
| 0-23 |
|
|
| 0-59 |
|
|
| 0.0000-59.9999 | includes millisecond as fraction |
|
| 0.0-999.9 | broken in 2.1, 2.1.1 |
MILLISECOND
Description
Firebird 2.1 and up support extraction of the millisecond from a TIME
or TIMESTAMP
. The datatype returned is NUMERIC(9,1)
.
If you extract the millisecond from |
WEEK
Description
Firebird 2.1 and up support extraction of the ISO-8601 week number from a DATE
or TIMESTAMP
. ISO-8601 weeks start on a Monday and always have the full seven days. Week 1 is the first week that has a majority (at least 4) of its days in the new year. The first 1-3 days of the year may belong to the last week (52 or 53) of the previous year. Likewise, a year’s final 1-3 days may belong to week 1 of the following year.
Be careful when combining Please also notice that |
See also