Truncates dates to a specific year, month, day, hour, or minute. You can also use TRUNC to truncate numbers.
You can truncate the following date parts:
•Year. If you truncate the year portion of the date, the function returns Jan 1 of the input year with the time set to 00:00:00. For example, the expression TRUNC(6/30/1997 2:30:55, 'YY') returns 1/1/1997 00:00:00, and TRUNC(12/1/1997 3:10:15, 'YY') returns 1/1/1997 00:00:00.
•Month. If you truncate the month portion of a date, the function returns the first day of the month with the time set to 00:00:00. For example, the expression TRUNC(4/15/1997 12:15:00, 'MM') returns 4/1/1997 00:00:00, and TRUNC(4/30/1997 3:15:46, 'MM') returns 4/1/1997 00:00:00.
•Day. If you truncate the day portion of a date, the function returns the date with the time set to 00:00:00. For example, the expression TRUNC(6/13/1997 2:30:45, 'DD') returns 6/13/1997 00:00:00, and TRUNC(12/13/1997 22:30:45, 'DD') returns 12/13/1997 00:00:00.
•Hour. If you truncate the hour portion of a date, the function returns the date with the minutes and seconds set to 0. For example, the expression TRUNC(4/1/1997 11:29:35, 'HH') returns 4/1/1997 11:00:00, and TRUNC(4/1/1997 13:39:00, 'HH') returns 4/1/1997 13:00:00.
•Minute. If you truncate the minute portion of a date, the function returns the date with the seconds set to 0. For example, the expression TRUNC(5/22/1997 10:15:29, 'MI') returns 5/22/1997 10:15:00, and TRUNC(5/22/1997 10:18:30, 'MI') returns 5/22/1997 10:18:00.
Syntax
TRUNC( date [,format] )
Argument
Required/
Optional
Description
date
Required
Date/Time datatype. The date values you want to truncate. You can enter any valid expression that evaluates to a date.
format
Optional
Enter a valid format string. The format string is not case sensitive. If you omit the format string, the function truncates the time portion of the date, setting it to 00:00:00.
Return Value
Date.
NULL if a value passed to the function is NULL.
Example
The following expressions truncate the year portion of dates in the DATE_SHIPPED column: