%TIMESTAMP (Convert to Timestamp)


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

Using %TIMESTAMP to return the current system timestamp

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

If the first parameter is *SYS, the optional second parameter is the number of fractional seconds in the returned timestamp. The number of fractional seconds can be between 0 and 12. It defaults to 6 fractional seconds.

If the first parameter is *UNIQUE, %TIMESTAMP returns the current system timestamp, accurate to microsecond precision. The first six digits of the fractional seconds portion of the timestamp are set to the microseconds portion of the timestamp. The remaining six fractional seconds are set to a value which makes the resulting timestamp unique. However, the remaining six fractional seconds do not provide greater precision for the timestamp.

Tip: If unique timestamps are used to determine the elapsed time between two unique timestamps, the result should only be calculated to microsecond precision.

Using %TIMESTAMP to convert an expression to a timestamp

  • If the first parameter is a character or numeric expression, the second parameter is the format of the character or numeric data. 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. The number of fractional seconds can be between 0 and 12. It defaults to 6 fractional seconds.

  • If the first parameter 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.

%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.421345

   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

   dsply (%timestamp(*UNIQUE);
    // It displays 2014-06-27-01.02.03.923481000244