Datetime assignments

Start of changeA value that is assigned to a date, time, or timestamp column or variable must be a date, time, or timestamp or a valid string representation of a date, a time, or a timestamp.End of change

A value assigned to a DATE column or a DATE variable must be a date Start of changeor timestampEnd of change or a valid string representation of a dateStart of change or timestampEnd of change. Start of changeWhen a timestamp value is assigned to a DATE data type, the date portion is extracted and the time portion is ignored.End of change A date can be assigned only to a DATE Start of changeor TIMESTAMPEnd of change column, a string column, a DATE Start of changeor TIMESTAMPEnd of change variable, or a string variable.

A value assigned to a TIME column or a TIME variable must be a time Start of changeor timestampEnd of change or a valid string representation of a time Start of changeor timestampEnd of change. Start of changeWhen a timestamp value is assigned to a TIME data type, the date portion is ignored and the time portion is extracted with the fractional seconds truncated.End of change A time can be assigned only to a TIME column, a string column, a TIME variable, or a string variable.

A value assigned to a TIMESTAMP column or a TIMESTAMP variable must be a Start of changedate orEnd of change timestamp or a valid string representation of a Start of changedate orEnd of change timestamp. If a string representation of a Start of changedate orEnd of change timestamp is used, it is implicitly cast to a timestamp with the same precision as the target timestamp. Start of changeWhen a date value is assigned to a TIMESTAMP data type, the missing time information is assumed to be all zeros.End of change A timestamp can be assigned to a Start of changeDATE, TIME, or End of changeTIMESTAMP column, a string column, a Start of changeDATE, TIME, orEnd of change TIMESTAMP variable, or a string variable. When a timestamp value is assigned to a timestamp with lower precision, the excess fractional seconds are truncated. When a timestamp value is assigned to a timestamp with higher precision, missing digits are assumed to be zeros.

When a datetime value is assigned to a string variable or column, it is converted to its string representation. Leading zeros are not omitted from any part of the date, time, or timestamp. The required length of the target varies depending on the format of the string representation. If the length of the target is greater than required, it is padded on the right with blanks. If the length of the target is less than required, the result depends on the type of datetime value involved and on the type of target.

  • If the target is a string column, truncation is not allowed. The following rules apply:

    DATE

    • The length attribute of the column must be at least 10 if the date format is *ISO, USA, *EUR, or *JIS. If the date format is *YMD, *MDY, or *DMY, the length attribute of the column must be at least 8. If the date format is *JUL, the length of the variable must be at least 6.

    TIME

    • The length attribute of the column must be at least 8.

    TIMESTAMP

    • Start of changeThe length attribute of the column must be at least 19 for TIMESTAMP(0) and 20+p for TIMESTAMP(p).End of change
  • When the target is a variable, the following rules apply:

    DATE

    • The length of the variable must be at least 10 if the date format is *ISO, *USA, *EUR, or *JIS. If the date format is *YMD, *MDY, or *DMY, the length of the variable must be at least 8. If the date format is *JUL, the length of the variable must be at least 6.

    TIME

    • If the *USA format is used, the length of the variable must not be less than 8. This format does not include seconds.
    • If the *ISO, *EUR, *JIS, or *HMS time format is used, the length of the variable must not be less than 5. If the length is 5, 6, or 7, the seconds part of the time is omitted from the result, and SQLWARN1 is set to 'W'. In this case, the seconds part of the time is assigned to the indicator variable if one is provided, and, if the length is 6 or 7, blank padding occurs so that the value is a valid string representation of a time.

    TIMESTAMP

    • The length of the variable must not be less than 19. Start of changeIf the length is between 19 and 31, the timestamp is truncated like a string, causing the omission of one or more digits of fractional seconds.End of change If the length is 20, the trailing decimal point is replaced by a blank so that the value is a valid string representation of a timestamp with a precision of 0.