TRUNC (Dates)
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:
TRUNC( DATE_SHIPPED, 'Y' )
TRUNC( DATE_SHIPPED, 'YY' )
TRUNC( DATE_SHIPPED, 'YYY' )
TRUNC( DATE_SHIPPED, 'YYYY' )
DATE_SHIPPED | RETURN VALUE |
---|
Jan 15 1998 2:10:30AM | Jan 1 1998 12:00:00AM |
Apr 19 1998 1:31:20PM | Jan 1 1998 12:00:00AM |
Jun 20 1998 3:50:04AM | Jan 1 1998 12:00:00AM |
Dec 20 1998 3:29:55PM | Jan 1 1998 12:00:00AM |
NULL | NULL |
The following expressions truncate the month portion of each date in the DATE_SHIPPED column:
TRUNC( DATE_SHIPPED, 'MM' )
TRUNC( DATE_SHIPPED, 'MON' )
TRUNC( DATE_SHIPPED, 'MONTH' )
DATE_SHIPPED | RETURN VALUE |
---|
Jan 15 1998 2:10:30AM | Jan 1 1998 12:00:00AM |
Apr 19 1998 1:31:20PM | Apr 1 1998 12:00:00AM |
Jun 20 1998 3:50:04AM | Jun 1 1998 12:00:00AM |
Dec 20 1998 3:29:55PM | Dec 1 1998 12:00:00AM |
NULL | NULL |
The following expressions truncate the day portion of each date in the DATE_SHIPPED column:
TRUNC( DATE_SHIPPED, 'D' )
TRUNC( DATE_SHIPPED, 'DD' )
TRUNC( DATE_SHIPPED, 'DDD' )
TRUNC( DATE_SHIPPED, 'DY' )
TRUNC( DATE_SHIPPED, 'DAY' )
DATE_SHIPPED | RETURN VALUE |
---|
Jan 15 1998 2:10:30AM | Jan 15 1998 12:00:00AM |
Apr 19 1998 1:31:20PM | Apr 19 1998 12:00:00AM |
Jun 20 1998 3:50:04AM | Jun 20 1998 12:00:00AM |
Dec 20 1998 3:29:55PM | Dec 20 1998 12:00:00AM |
Dec 31 1998 11:59:59PM | Dec 31 1998 12:00:00AM |
NULL | NULL |
The following expressions truncate the hour portion of each date in the DATE_SHIPPED column:
TRUNC( DATE_SHIPPED, 'HH' )
TRUNC( DATE_SHIPPED, 'HH12' )
TRUNC( DATE_SHIPPED, 'HH24' )
DATE_SHIPPED | RETURN VALUE |
---|
Jan 15 1998 2:10:31AM | Jan 15 1998 2:00:00AM |
Apr 19 1998 1:31:20PM | Apr 19 1998 1:00:00PM |
Jun 20 1998 3:50:04AM | Jun 20 1998 3:00:00AM |
Dec 20 1998 3:29:55PM | Dec 20 1998 3:00:00PM |
Dec 31 1998 11:59:59PM | Dec 31 1998 11:00:00AM |
NULL | NULL |
The following expression truncates the minute portion of each date in the DATE_SHIPPED column:
TRUNC( DATE_SHIPPED, 'MI' )
DATE_SHIPPED | RETURN VALUE |
---|
Jan 15 1998 2:10:30AM | Jan 15 1998 2:10:00AM |
Apr 19 1998 1:31:20PM | Apr 19 1998 1:31:00PM |
Jun 20 1998 3:50:04AM | Jun 20 1998 3:50:00AM |
Dec 20 1998 3:29:55PM | Dec 20 1998 3:29:00PM |
Dec 31 1998 11:59:59PM | Dec 31 1998 11:59:00PM |
NULL | NULL |