Extract

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > String Functions >

Extract

Returns the year, month, or day field from a DATE column.

Syntax:

EXTRACT(extract_field FROM column_reference)

Example:

SELECT saledate,

EXTRACT(YEAR FROM saledate) AS YY,

EXTRACT(MONTH FROM saledate) AS MM,

EXTRACT(DAY FROM saledate) AS DD

FROM orders

 

The statement below uses a DOB column (containing birth dates) to filter to those rows where the date is in the month of May. The month field from the DOB column is retrieved using the EXTRACT function and compared to 5, May being the fifth month.

SELECT DOB, LastName, FirstName FROM People

WHERE (EXTRACT(MONTH FROM DOB) = 5)