Overview
TheDATE_TRUNC()
function truncates a timestamp, timestamp with time zone or interval value to the specified precision,
effectively rounding down the value to the start of the given time unit. The return type matches the input type.
Syntax
The syntax for using theDATE_TRUNC()
function is as follows:
Parameters
field
: The unit of time used to truncate thesource
value. It acceptstext
inputs and is case-insensitivesource
: The value you want to truncate. It can beINTERVAL
,TIMESTAMP
orTIMESTAMP WITH TIME ZONE
time_zone
(applicable for the second syntax option): The time zone for the operation. It acceptstext
input
Fields
Below is a list of supported values to specify the fields param inDATE_TRUNC()
syntax.
microseconds
milliseconds
second
minute
hour
day
week
month
quarter
year
decade
century
millennium
Some fields like
microseconds
and milliseconds
are supported only for interval types.