TRUNC_TIMESTAMP

The TRUNC_TIMESTAMP function returns a timestamp that is the expression truncated to the unit specified by the format-string. If format-string is not specified, expression is truncated to the nearest day, as if 'DD' was specified for format-string.

Read syntax diagramSkip visual syntax diagram
                                   .-,--'DD'----------.      
>>-TRUNC_TIMESTAMP--(--expression--+------------------+--)-----><
                                   '-,--format-string-'      

expression
An expression that returns a value of one of the following built-in data types: a timestamp, a character-string, or a graphic-string.
If expression is a character or graphic string, it must not be a CLOB or DBCLOB and its value must be a valid string representation of a timestamp. For the valid formats of string representations of timestamps, see String representations of datetime values.
format-string
An expression that returns a built-in character string data type or graphic string data type Start of changethat is not a CLOB or DBCLOB.End of change format-string contains a template of how the timestamp represented by expression should be truncated. For example, if format-string is 'DD', the timestamp that is represented by expression is truncated to the nearest day. Leading and trailing blanks are removed from the string, and the resulting substring must be a valid template for a timestamp. The resulting value is then folded to uppercase, so the characters in the value may be in any case. Start of changeThe resulting substring must be a valid format element for a timestamp.End of change

Allowable values for format-string are listed in Table 1.

The result of the function is a TIMESTAMP. If either argument can be null, the result can be null; if either argument is null, the result is the null value.

Example

  • Set the host variable TRN_TMSTMP with the current year rounded to the nearest year value.
      SET :TRN_TMSTMP = TRUNC_TIMESTAMP('2000-03-14-17.30.00', 'YEAR');
    Host variable TRN_TMSTMP is set with the value 2000-01-01-00.00.00.000000.