PostgreSQL DATE PART Function

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL DATE_PART() function

DATE_PART() function

The date_part() function is used to return the part of a date and time.

Syntax :

date_part(text, timestamp)
or
date_part(text, interval)

Return Type : double precision.

PostgreSQL Version : 9.3

Pictorial Presentation of PostgreSQL DATE_PART() function

 

Example 1 : PostgreSQL DATE_PART() function

The example below finds the hour part from the timestamp (date and time specified in the argument) .

SELECT date_part('hour', timestamp '2002-09-17 19:27:45');

Output :

 date_part
-----------
        19
(1 row)

Example 2: PostgreSQL DATE_PART() function

The example below extracts the months part the given age.

SELECT date_part('month', interval '3 years 7 months');

Output :

 date_part
-----------
         7
(1 row)