TRUNC
Description
TRUNC
is a row function that truncates a DATE
value to the specified format.Syntax
TRUNC
(date
, "format
")Return Value
Returns a value of type
DATE
truncated to the specified format.Input Parameters
- date
- Required. A field or expression that returns aDATEvalue.
- format
- Required. One of the following format values:
- - Returns a date value truncated to millisecond granularity. Has no effect since millisecond is already the most granular format for date values. For example, an input date value ofmillisecond2012-08-15 20:38:40.213would return a date value of2012-08-15 20:38:40.213.
- - Returns a date value truncated to second granularity. For example, an input date value ofsecond2012-08-15 20:38:40.213would return a date value of2012-08-15 20:38:40.000.
- - Returns a date value truncated to minute granularity. For example, an input date value ofminute2012-08-15 20:38:40.213would return a date value of2012-08-15 20:38:00.000.
- - Returns a date value truncated to hour granularity. For example, an input date value ofhour2012-08-15 20:38:40.213would return a date value of2012-08-15 20:00:00.000.
- - Returns a date value truncated to day granularity. For example, an input date value ofday2012-08-15 20:38:40.213would return a date value of2012-08-15 00:00:00.000.
- - Returns a date value truncated to the first day of the week (starting on a Monday). For example, an input date value ofweek2012-08-15(a Wednesday) would return a date value of2012-08-13(the Monday prior).
- - Returns a date value truncated to the first day of the month. For example, an input date value ofmonth2012-08-15would return a date value of2012-08-01.
- - Returns a date value truncated to the first day of the quarter (January 1, April 1, July 1, or October 1). For example, an input date value ofquarter2012-08-15 20:38:40.213would return a date value of2012-07-01.
- - Returns a date value truncated to the first day of the year (January 1). For example, an input date value ofyear2012-08-15would return a date value of2012-01-01.
- - Returns a date value trucated to the first day of the ISO weekyear (the ISO week starting with the Monday which is nearest in time to January 1). For example, an input date value ofweekyear2008-08-15would return a date value of2007-12-31. The first day of the ISO weekyear for 2008 is December 31, 2007 (the prior Monday closest to January 1).
Examples
Truncate the
order_date
date field to day granularity:TRUNC([order_date],"day")
Cast the value of the
order_date
TEXT
field to a date value using TO_DATE
, and truncate it to day granularity:TRUNC(TO_DATE([order_date], "MM/dd/yyyy HH:mm:ss"), "day")