TRUNC_TIMESTAMP

The TRUNC_TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value that is the expression, truncated to the unit that is specified by the format-string.

Read syntax diagramSkip visual syntax diagramTRUNC_TIMESTAMP(expression 'DD',format-string )

The schema is SYSIBM.

expression
An expression that returns a value of any 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 with an actual length that is not greater than 255 bytes. A time zone in a string representation of a timestamp is ignored. For the valid formats of string representations of dates and timestamps, see String representations of datetime values.
format-string
An expression that returns a built-in character string or graphic string data type, with a length that is not greater than 255 bytes. 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. format-string must be a valid template for a timestamp, and not include leading or trailing blanks. Allowable values for format-string are listed in the following table.
Table 1. ROUND_TIMESTAMP and TRUNC_TIMESTAMP format models
Format model Rounding or truncating unit ROUND_TIMESTAMP example TRUNC_TIMESTAMP example
CC
SCC

Century

Rounds up to the start of the next century after the 50th year of the century (for example on 1951–01–01–00.00.00).

Not valid for a TIME argument.

Input Value:
1897-12-04-12.22.22.000000
Result:
1901-01-01-00.00.00.000000
Input Value:
1897-12-04-12.22.22.000000
Result:
1801-01-01-00.00.00.000000
SYYYY
YYYY
YEAR
SYEAR
YYY
YY
Y
Year (Rounds up on July 1st)
Input Value:
1897-12-04-12.22.22.000000
Result:
1898-01-01-00.00.00.000000
Input Value:
1897-12-04-12.22.22.000000
Result:
1897-01-01-00.00.00.000000
IYYY
IYY
IY
I
ISO Year (Rounds up on July 1st)
Input Value:
1897-12-04-12.22.22.000000
Result:
1898-01-03-00.00.00.000000
Input Value:
1897-12-04-12.22.22.000000
Result:
1897-01-04-00.00.00.000000
Q Quarter (Rounds up on the sixteenth day of the second month of the quarter)
Input Value:
1999-06-04-12.12.30.000000
Result:
1999-07-01-00.00.00.000000
Input Value:
1999-06-04-12.12.30.000000
Result:
1999-04-01-00.00.00.000000
MONTH
MON
MM
RM
Month (Rounds up on the sixteenth day of the month)
Input Value:
1999-06-18-12.12.30.000000
Result:
1999-07-01-00.00.00.000000
Input Value:
1999-06-18-12.15.00.000000
Result:
1999-06-01-00.00.00.000000
WW Same day of the week as the first day of the year (Rounds up on the 12th hour of the 3rd day of the week, with respect to the first day of the year)
Input Value:
2000-05-05-12.12.30.000000
Result:
2000-05-06-00.00.00.000000
Input Value:
2000-05-05-12.15.00.000000
Result:
2000-04-29-00.00.00.000000
IW Same day of the week as the first day of the ISO year (Rounds up on the 12th hour of the 3rd day of the week, with respect to the first day of the ISO year)
Input Value:
2000-05-05-12.12.30.000000
Result:
2000-05-08-00.00.00.000000
Input Value:
2000-05-05-12.15.00.000000
Result:
2000-05-01-00.00.00.000000
W Same day of the week as the first day of the month (Rounds up on the 12th hour of the 3rd day of the week, with respect to the first day of the month)
Input Value:
2000-05-17-12.12.30.000000
Result:
2000-05-15-00.00.00.000000
Input Value:
2000-05-17-12.15.00.000000
Result:
2000-05-15-00.00.00.000000
DDD
DD
J
Day (Rounds up on the 12th hour of the day)
Input Value:
2000-05-17-12.59.59.000000
Result:
2000-05-18-00.00.00.000000
Input Value:
2000-05-17-12.59.59.000000
Result:
2000-05-17-00.00.00.000000
DAY
DY
D
Starting day of the week (Rounds up with respect to the 12th hour of the third day of the week. The first day of the week is always Sunday).
Input Value:
2000-05-17-12.59.59.000000
Result:
2000-05-21-00.00.00.000000
Input Value:
2000-05-17-12.59.59.000000
Result:
2000-05-14-00.00.00.000000
HH
HH12
HH24
Hour (Rounds up at 30 minutes)
Input Value:
2000-05-17-23.59.59.000000
Result:
2000-05-18-00.00.00.000000
Input Value:
2000-05-17-23.59.59.000000
Result:
2000-05-17-23.00.00.000000
MI Minute (Rounds up at 30 seconds)
Input Value:
2000-05-17-23.58.45.000000
Result:
2000-05-17-23.59.00.000000
Input Value:
2000-05-17-23.58.45.000000
Result:
2000-05-17-23.58.00.000000
SS Second (Rounds up at 500000 microseconds)
Input Value:
2000-05-17-23.58.45.500000
Result:
2000-05-17-23.58.46.000000
Input Value:
2000-05-17-23.58.45.500000
Result:
2000-05-17-23.58.45.000000

Start of changeexpression is cast as follows:End of change

  • Start of changeIf expression is a timestamp with time zone value, expression is cast to a timestamp without time zone value, with the same precision as expression.End of change
  • Otherwise, expression is cast to TIMESTAMP(6) WITHOUT TIME ZONE.

Start of changeThe result of the function is a timestamp with time zone.End of change

The result can be null; if any argument is null, the result is the null value.

The result CCSID is the appropriate CCSID of the argument encoding scheme and the result subtype is the appropriate subtype of the CCSID.

Example: Set the host variable TRNK_TMSTMP with the specified date rounded to the nearest year value.
   SET :TRNK_TMSTMP = TRUNC_TIMESTAMP('2008-03-14-17.30.00', 'YEAR'); 
The host variable TRNK_TMSTMP is set with the value '2008-01-01-00.00.00.000000'.