EXTRACT()
function retrieves a specified part (field) from a given date/time or interval value.
It is commonly used to obtain components such as year, month, day, hour, etc., from timestamps or dates.
field
: string or identifier specifying the part of the date / time to extractsource
: date / time value from which to extract the specifed fieldEXTRACT()
function:
Input Type: source | Supported field values | Return Type |
---|---|---|
TIMESTAMP | YEAR , MONTH , DAY , HOUR , MINUTE , SECOND | DOUBLE PRECISION |
TIMESTAMPTZ | YEAR , MONTH , DAY , HOUR , MINUTE , SECOND | DOUBLE PRECISION |
DATE | YEAR , MONTH , DAY | INTEGER |
EXTRACT()
function to extract a given timestamp’s YEAR:
EXTRACT()
function to extract a given timestamp’s MONTH:
EXTRACT()
function to extract a given timestamp’s SECONDS: