DATE_TRUNC

Purpose

This is a PostgreSQL compatible function to round down date and timestamp values.

Syntax

date_trunc::=

Date Trunc

Usage Notes

  • As format you can use one of the following elements: 'microseconds', 'milliseconds', 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year', 'decade', 'century', 'millennium'.
  • The first day of a week (for format element 'week') is defined by the parameter NLS_FIRST_DAY_OF_WEEK (also see ALTER SESSION and ALTER SYSTEM).
  • A similar functionality provides the Oracle compatible function TRUNC[ATE] (datetime).
  • For data type TIMESTAMP WITH LOCAL TIME ZONE this function is calculated within the session time zone.

Examples

SELECT DATE_TRUNC('month', DATE '2006-12-31') DATE_TRUNC;
SELECT DATE_TRUNC('minute', TIMESTAMP '2006-12-31 23:59:59') DATE_TRUNC;