%TIMESTAMP (Convert to Timestamp)


%TIMESTAMP{(char-num-expression { : *ISO|*ISO0 : {fractional-seconds}})}
%TIMESTAMP{(date-timestamp-expression { : fractional-seconds})}

If you do not specify a parameter, or if you specify *SYS as the first parameter, %TIMESTAMP returns the current system timestamp.

%TIMESTAMP converts the value of the expression from character, numeric, date or timestamp data to type timestamp. The converted value is returned as a timestamp.

The first parameter is the value to be converted. If you do not specify a value, %TIMESTAMP returns the current system timestamp. Only the first three digits of the fractional seconds portion of the timestamp will be set to a non-zero value. The remaining fractional seconds will be zero.

  • If the first parameter is a character or numeric expression, the second parameter is the timestamp format. Regardless of the input format, the output is returned in *ISO format.

    For character input, you can specify either *ISO (the default) or *ISO0. For more information, see Timestamp Data Type.

    If the first parameter is numeric, you do not need to specify the second parameter. The only allowed value is *ISO (the default).

    The optional third parameter is the number of fractional seconds in the timestamp.

  • If the first parameter is *SYS or a date or timestamp expression, the optional second parameter is the number of fractional seconds in the returned timestamp.

    If the first operand is a date, the system converts the date from its current format to *ISO format and adds a time of 00.00.00 and zero fractional seconds.

The number of fractional seconds can be between 0 and 12. It defaults to 6 fractional seconds.

For more information, see Information Operations or Built-in Functions.

Figure 1. %TIMESTAMP Example
 *..1....+....2....+....3....+....4....+....5....+....6....+....7...+....

   string = '1960-09-29-12.34.56.000000';
   timest =  %timestamp(string);
    // timest now contains z'1960-09-29-12.34.56.000000'

   date = '2001-03-05';
   timest =  %timestamp(date);
    // timest now contains z'2001-03-05-00.00.00.000000'

   dsply (%timestamp(*SYS));
    // It displays 2014-06-27-01.02.03.421000

   dsply (%timestamp(*SYS : 1));
    // It displays 2014-06-27-01.02.03.4

   dsply (%timestamp(*SYS : 0));
    // It displays 2014-06-27-01.02.03