Transformation Language Reference > Functions > TRUNC (Dates)
  

TRUNC (Dates)

Truncates dates to a specific year, month, day, hour, minute, second, millisecond, or microsecond. You can also use TRUNC to truncate numbers.
You can truncate the following date parts:

Syntax

TRUNC( date [,format] )
The following table describes the arguments for this command:
Argument
Required/
Optional
Description
date
Required
Date/Time datatype. The date values you want to truncate. You can enter any valid transformation 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.000000000.

Return Value

Date.
NULL if a value passed to the function is NULL.

Examples

The following expressions truncate the year portion of dates in the DATE_SHIPPED port:
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:00.000000000
Apr 19 1998 1:31:20PM
Jan 1 1998 12:00:00.000000000
Jun 20 1998 3:50:04AM
Jan 1 1998 12:00:00.000000000
Dec 20 1998 3:29:55PM
Jan 1 1998 12:00:00.000000000
NULL
NULL
The following expressions truncate the month portion of each date in the DATE_SHIPPED port:
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:00.000000000AM
Apr 19 1998 1:31:20PM
Apr 1 1998 12:00:00.000000000AM
Jun 20 1998 3:50:04AM
Jun 1 1998 12:00:00.000000000AM
Dec 20 1998 3:29:55PM
Dec 1 1998 12:00:00.000000000AM
NULL
NULL
The following expressions truncate the day portion of each date in the DATE_SHIPPED port:
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:00.000000000AM
Apr 19 1998 1:31:20PM
Apr 19 1998 12:00:00.000000000AM
Jun 20 1998 3:50:04AM
Jun 20 1998 12:00:00.000000000AM
Dec 20 1998 3:29:55PM
Dec 20 1998 12:00:00.000000000AM
Dec 31 1998 11:59:59PM
Dec 31 1998 12:00:00.000000000AM
NULL
NULL
The following expressions truncate the hour portion of each date in the DATE_SHIPPED port:
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:00.000000000AM
Apr 19 1998 1:31:20PM
Apr 19 1998 1:00:00.000000000PM
Jun 20 1998 3:50:04AM
Jun 20 1998 3:00:00.000000000AM
Dec 20 1998 3:29:55PM
Dec 20 1998 3:00:00.000000000PM
Dec 31 1998 11:59:59PM
Dec 31 1998 11:00:00.000000000AM
NULL
NULL
The following expression truncates the minute portion of each date in the DATE_SHIPPED port:
TRUNC( DATE_SHIPPED, 'MI' )
DATE_SHIPPED
RETURN VALUE
Jan 15 1998 2:10:30AM
Jan 15 1998 2:10:00.000000000AM
Apr 19 1998 1:31:20PM
Apr 19 1998 1:31:00.000000000PM
Jun 20 1998 3:50:04AM
Jun 20 1998 3:50:00.000000000AM
Dec 20 1998 3:29:55PM
Dec 20 1998 3:29:00.000000000PM
Dec 31 1998 11:59:59PM
Dec 31 1998 11:59:00.000000000PM
NULL
NULL