A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-extract-function/ below:

PostgreSQL - EXTRACT Function - GeeksforGeeks

PostgreSQL - EXTRACT Function

Last Updated : 15 Jul, 2025

In PostgreSQL, the EXTRACT() function is a powerful tool used to retrieve specific components of a date or time value. Whether you need to query for a particular year, month, day, or even more detailed time attributes, EXTRACT() can help you extract these fields from date and time values efficiently.

From this article, we can better understand the EXTRACT Function in PostgreSQL.

Syntax
EXTRACT(field FROM source)
Parameters

Let's analyze the above syntax:

PostgreSQL EXTRACT Function Examples

Now let us take a look at some of the examples of EXTRACT() Function in PostgreSQL to better understand the concept.

Example 1: Extracting the Year

The below statement extracts year from a timestamp.

Query:

SELECT EXTRACT(YEAR FROM TIMESTAMP '2020-12-31 13:30:15');

Output:

Explanation: The output will display the year extracted from the given timestamp, which is '2020'.

Example 2: Extracting the Quarter

The below statement extracts the quarter from a timestamp.

Query:

SELECT EXTRACT(QUARTER FROM TIMESTAMP '2020-12-31 13:30:15');

Output:

Explanation: The output will show the quarter of the year, which is '4' for the given timestamp.

Example 3: Extracting the Month

The below statement extracts month from a timestamp.

Query:

SELECT EXTRACT(MONTH FROM TIMESTAMP '2020-12-31 13:30:15');

Output:

Explanation: The output will be '12', indicating December.

Important Points About PostgreSQL EXTRACT Function


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4