DATE_PART_YEAR function - Amazon Redshift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

DATE_PART_YEAR function

The DATE_PART_YEAR function extracts the year from a date.

Syntax

DATE_PART_YEAR(date)

Argument

date

A column of data type DATE or an expression that implicitly evaluates to a DATE type.

Return type

INTEGER

Examples

The following example finds the year from a date literal.

SELECT DATE_PART_YEAR(date '20220502 04:05:06.789'); date_part_year --------------- 2022

The following example extracts the year from the CALDATE column. The values in the CALDATE column are dates. For more information about the data used in this example, see Sample database.

select caldate, date_part_year(caldate) from date order by dateid limit 10; caldate | date_part_year -----------+---------------- 2008-01-01 | 2008 2008-01-02 | 2008 2008-01-03 | 2008 2008-01-04 | 2008 2008-01-05 | 2008 2008-01-06 | 2008 2008-01-07 | 2008 2008-01-08 | 2008 2008-01-09 | 2008 2008-01-10 | 2008 (10 rows)