Timestamp
EXTRACT
Overview
The EXTRACT()
function takes out a given part (field) from a specified source.
Syntax
Parameters
field
: string or identifier specifying the part of the date / time to extractsource
: date / time value to extract from
The table below shows the supported input and return types for the EXTRACT()
function:
Input Type: source | field | Return Type |
---|---|---|
TIMESTAMP | YEAR , MONTH , DAY , HOUR , MINUTE , SECOND | BIGINT |
TIMESTAMPTZ | YEAR , MONTH , DAY , HOUR , MINUTE , SECOND | BIGINT |
DATE | YEAR , MONTH , DAY | INTEGER |
Examples
EXTRACT() with Timestamp - Year
The below example uses the EXTRACT()
function to extract a given timestamp’s YEAR:
The final output will be as follows:
EXTRACT() with Timestamp - Month
Here we will use the EXTRACT()
function to extract a given timestamp’s MONTH:
The final output will take the month’s part of a given timestamp: