Conversion instructions
231
Part II IEC Instructions
TIME_TO_STRING
TIME into STRING
To add an enable input and enable output to the instruction, select [With EN/ENO] from the
"Instructions" pane (LD, FBD or IL editor). To reuse an instruction select "Recently used" from the
context menu or press <Ctrl>+<Shift>+<v> in the programming window.
When using the data type STRING with small PLCs like FP1 or FP-M, make
sure that the length of the result string is equal to or greater than the length of
the source string.
PLC types
Availability of TIME_TO_STRING (see page 1331)
Data type I/O Function
TIME input input data type
STRING output conversion result
Description
The function TIME_TO_STRING converts a value of the data type TIME to a value of the data type
STRING[20]. In accordance with IEC-1131, the result string is displayed with a short time prefix
and without underlines. Possible values for the result string’s range are from
'T#000d00h00m00s000ms' to 'T#248d13h13m56s470ms'.
Data types
Example 1
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
In the POU header, input and output variables are declared that are used in the function.
The input variable input_value of the data type TIME is intialized by the value T#1h30m45s. The
output variable result_string is of the data type STRING[20]. It can store a maximum of 20
characters. Instead of using the variable input_value, you can enter a constant directly at the
function’s input contact in the body.
Body
The input_value of the data type TIME is converted into STRING[20]. The converted value is
written to result_string. When the variable input_value = T#1h30m45s, result_string shows
'T#000d01h30m45s000ms'.
LD
ST
When programming with structured text, enter the following:
result_string:=TIME_TO_STRING(input_value);