PostgreSQL DATE TRUNC Function

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

PostgreSQL DATE_TRUNC() function

DATE_TRUNC() function

The date_trunc() function is used to truncate to specified precision.

Syntax :

date_trunc(text, timestamp)

Return Type : timestamp.

PostgreSQL Version : 9.3

Pictorial Presentation of PostgreSQL DATE_TRUNC() function

Example : PostgreSQL DATE_TRUNC() function :

Example :

  1. SELECT date_trunc('hour'timestamp '2002-09-17 19:27:45');  

Output :

     date_trunc
---------------------
 2002-09-17 19:00:00
(1 row)