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
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook