Skip to main content Skip to complementary content

EXTRACT

Extracts a unit of time as a field from the given timestamp.

Syntax

EXTRACT(FIELD FROM X)

Arguments

FIELD

Type: identifier

The unit of time to extract.

The following fields are supported:

Field Description
YEAR year
QUARTER quarter
MONTH month
WEEK week
DAY day
DAY_OF_MONTH day
DAY_OF_WEEK day of week
DOW day of week
DAY_OF_YEAR day of year
DOY day of year
YEAR_OF_WEEK year of week
YOW year of week
HOUR hour
MINUTE minute
SECOND second

X

Type: timestamp

The time to extract FIELD from.

Returns

Type: bigint

The FIELD extracted from X.


Examples

Field X Output
year 2012-02-22 00:00:00 2012
month 2012-02-22 00:00:00 02
day 2012-02-22 00:00:00 22
hour 2012-02-22 00:00:00 01
minute 2012-02-22 01:02:00 02
second 2012-02-22 01:00:32 21
dow 2012-02-22 01:00:32 3
dow null null

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!