All Products
Search
Document Center

PolarDB:EXTRACT

Last Updated:Mar 28, 2026

EXTRACT retrieves a subfield such as year or hour from a date/time value.

Syntax

EXTRACT(field FROM source)

Arguments

ArgumentDescription
fieldThe subfield to extract. See Supported subfields for valid values.
sourceA date/time value, typically a TIMESTAMP expression.

Return type

DOUBLE PRECISION

Supported subfields

SubfieldDescriptionRange
YEARThe year
MONTHThe month within the year1–12
DAYThe day of the month1–31
HOURThe hour of the day0–23
MINUTEThe minute of the hour0–59
SECONDThe second of the minute, including the fractional part0–59

Examples

All examples use the same input timestamp: TIMESTAMP '2001-02-16 20:38:40'.

Extract the year:

SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
      2001
(1 row)

Extract the month:

SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
         2
(1 row)

Extract the day:

SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
        16
(1 row)

Extract the hour:

SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
        20
(1 row)

Extract the minute:

SELECT EXTRACT(MINUTE FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
        38
(1 row)

Extract the second:

SELECT EXTRACT(SECOND FROM TIMESTAMP '2001-02-16 20:38:40') FROM DUAL;
 date_part
-----------
        40
(1 row)