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) .
code:
SELECT date_part('hour', timestamp '2002-09-17 19:27:45');
Sample Output:
date_part ----------- 19 (1 row)
Example 2: PostgreSQL DATE_PART() function
The example below extracts the months part the given age.
Code:
SELECT date_part('month', interval '3 years 7 months');
Sample Output:
date_part ----------- 7 (1 row)
Previous: CURRENT_TIMESTAMP function
Next: DATE_TRUNC function
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- 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