DATE_TRUNC Function

Returns a new date by finding the nearest specified calendar or clock division prior to the specified source date.

Syntax

DATE_TRUNC(date-part, date)

Parameters

Return Value

A string like "2016-07-23 21:00:00.000 -04:00", calculated by finding the nearest specified time division prior to the specified date.

Example

-- Prints "2016-07-01 00:00:00.000".
PRINT DATE_TRUNC('month', '2016-07-23 12:23:00');

-- Prints "2015-08-02 00:00:00.000". PRINT DATE_TRUNC('week', '2015-08-03 12:41:25');

-- Prints "2015-02-03 12:00:00.000".
PRINT DATE_TRUNC('hh', '2015-02-03 12:41:25');