PostgreSQL EXTRACT() function
EXTRACT() function
The date_trunc() function is used to get subfield.
The extract function() is used to retrieves subfields such as year or hour from date/time values. The source must be a value expression of type timestamp, time, or interval. The field is an identifier or string that selects what field to be extracted from the source value.
Syntax:
extract(field from timestamp) or extract(field from interval)
Return Type: double precision.
PostgreSQL Version: 9.3
Pictorial Presentation of PostgreSQL EXTRACT() function

Example 1: PostgreSQL EXTRACT() function
Code:
SELECT extract(hour from timestamp '2002-09-17 19:27:45');
Sample Output:
date_part ----------- 19 (1 row)
Example 2: PostgreSQL EXTRACT() function
Code:
SELECT extract(month from interval '3 years 7 months');
Sample Output:
date_part ----------- 7 (1 row)
Previous: DATE_TRUNC function
Next: ISFINITE function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework