extract()

A function for retrieving elements of a date or time value

extract() is a system function for retrieving elements of a date or time value.

extract() has always been present in PostgreSQL.

Usage

PostgreSQL 14 and later:

extract ( field from timestamp ) → numeric
extract ( field from interval ) → numeric

PostgreSQL 13 and earlier:

extract ( field from timestamp ) → double precision
extract ( field from interval ) → double precision

Change history

Examples

Basic usage example for extract():

postgres=# SELECT extract('year' FROM now());
 extract 
---------
    2021
(1 row)

Categories

System function

See also

date_part()