DATE_TRUNC truncates a TIMESTAMP to the specified precision.

Syntax

DATE_TRUNC ( precision, dateTimeToTruncate )

Arguments

  • precision - The precision for the return value. Potential values are year, month, day, hour, minute, quarter, and week. precision is not case sensitive.
  • dateTimeToTruncate - A DATE, TIME, or TIMESTAMP value to truncate.

Returns

  • A TIMESTAMP.

Examples

SELECT DATE_TRUNC(year, '2013-07-23 23:59:59'), 
DATE_TRUNC(month, '2013-07-23 23:59:59'),
DATE_TRUNC(Day, '2013-07-23 23:59:59'), 
DATE_TRUNC(Hour, '2013-07-23 23:59:59'),
DATE_TRUNC(minute, '2013-07-23 23:59:59'), 
DATE_TRUNC(quarter, '2013-07-23 23:59:59'),
DATE_TRUNC(week, '2013-07-23 23:59:59')
FROM "redshift1.inventory.sampleData";

-- Returns
2013-01-01 00:00:00.0 2013-07-01 00:00:00.0 2013-07-23 00:00:00.0 2013-07-23 23:00:00.0   2013-07-23 23:59:00.0 2013-07-01 00:00:00.0 2013-07-