TIME

The TIME function returns a time that is derived from a value.

Read syntax diagram
>>-TIME(expression)--------------------------------------------><

The schema is SYSIBM.

The argument must be an expression that returns a value of one of the following built-in data types: a time, 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 time or timestamp with an actual length of not greater than 255 bytes. Start of changeA time zone in a string representation of a timestamp is ignored.End of change For the valid formats of string representations of times and timestamps, see String representations of datetime values.

Start of changeIf expression is a TIMESTAMP WITH TIME ZONE value, expression is first cast to TIMESTAMP WITHOUT TIME ZONE, with the same precision as expression.End of change

Start of changeIf expression is not a TIME value, expression is cast as follows:End of change

Start of change
  • If expression is a TIMESTAMP WITH TIME ZONE value, expression is cast to TIMESTAMP WITHOUT TIME ZONE, with the same precision as expression.
  • If expression is a string, expression is cast to TIME.
End of change

The result of the function is a time.

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

The other rules depend on the data type of the argument:

If the argument is a time
the result is that time.
If the argument is a timestamp
the result is the time part of the timestamp.
If the argument is a string
the result is the time or time part of the timestamp represented by the string. If the CCSID of the string is not the same as the corresponding default CCSID at the server, the string is first converted to that CCSID.

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

Example: Assume that a table named CLASSES contains one row for each scheduled class. Assume also that the class starting times are in the TIME column named STARTTM. Using these assumptions, select those rows in CLASSES that represent classes that start at 1:30 P.M.
   SELECT *
     FROM CLASSES
     WHERE TIME(STARTTM) = '13:30:00';