TIME_TO_STRING

TIME into STRING

The function TIME_TO_STRING converts a value of the data type TIME into 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'.

Parameters

Input

Unnamed input (TIME)
Input data type

Output

Unnamed output (STRING)
Conversion result

Remarks

When using the data type STRING with small PLCs like FP-e or FP0, make sure that the length of the result string is equal to or greater than the length of the source string.

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		input_value: TIME:=T#0s;
		result_string: STRING;

The input variable input_value of the data type TIME is initialized 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.

POU 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 body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,TIME_TO_STRING!,Instance,10,1,19,3,,?D?C);
B(B_VARIN,,input_value,8,1,10,3,);
B(B_VAROUT,,result_string,19,1,21,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

result_string:=TIME_TO_STRING(input_value);

IL body

Example

POU header

This example shows how, from an input value of the data type TIME, a string STRING[9] with the format 'xxhxxmxxs' is created (only hours, minutes and seconds are output).All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		input_value: TIME:=T#1h30m45s;
			(*example value*)
		result_string: STRING[9]:='';
			(*result: here '01h30m45s'*)
	END_VAR

In this example, both an input variable input_value of the data type TIME and an output variable result_string of the data type STRING[9] are declared.

POU body

In carrying out the operation in question, the standard function MID is attached to the function TIME_TO_STRING. MID creates a central sector in the character string from position P (INT value) with L (INT value) characters.

In the example, the INT constant 9 is entered at the L input of MID, which determines the length of the result string. The INT constant 7 at input P determines the position at which the central sector begins. Out of the variable input_value = T#1h30m45s, the STRING 'T#000d01h30m45s000ms' results from the data type conversion. The MID function cuts off the STRING at position 7 and yields the result_string '01h30m45s'.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,TIME_TO_STRING!,Instance,7,2,16,4,,?D?C);
B(B_VARIN,,input_value,5,2,7,4,);
B(B_VAROUT,,result_string,24,2,26,4,);
B(B_F,MID!,Instance,19,1,24,6,,?DIN?DL?DP?C);
B(B_VARIN,,9,17,3,19,5,);
B(B_VARIN,,7,17,4,19,6,);
L(1,0,1,6);
L(16,3,19,3);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

IL body

Modified on: 2019-01-24Feedback on this pagePanasonic hotline