Time conversion

Time conversion 1:

Undefined result if the value range is exceeded

If the input value of a type conversion operator is outside the value range of the output data type, the result of the operation is not defined and depends on the platform. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT. An exception error is also possible!

Time conversion 2:

Loss of information possible

If a larger data type is converted to a smaller data type, information may be lost.

Time conversion 3:

String manipulation when converting to STRING or WSTRING

With a type conversion to STRING or WSTRING, the typed value is stored as a left aligned string and truncated if it is overlong. Therefore, declare the return variables for the type conversion operators <type>_TO_STRING and <type>_TO_WSTRING long enough to accommodate the string without manipulation.

TIME_TO_<type>

The operators are used to convert the TIME or LTIME data type to another data type.

You can specify a variable or a literal as the operand.

Syntax:

TIME_TO_<Datentyp> (<Variablenname> | <Literal>)
LTIME_TO_<Datentyp> (<Variablenname> | <Literal>)

Converting TIME/LTIME to BOOL

Operators:

TIME_TO_BOOL (<Variablenname> | <Literal>)
LTIME_TO_BOOL (<Variablenname> | <Literal>)

The operator returns a FALSE exactly at the time when the operand value can be interpreted as “0”.

Examples:

ST code

Result

TIME_TO_BOOL(T#0MS);

FALSE

TIME_TO_BOOL(T#0NS);

FALSE

TIME_TO_BOOL(T#1MS);

TRUE

TIME_TO_BOOL(T#1NS);

TRUE

Converting TIME/LTIME to STRING/WSTRING

Operators:

TIME_TO_STRING (<Variablenname> | <Literal>)
LTIME_TO_STRING (<Variablenname> | <Literal>)
TIME_TO_WSTRING (<Variablenname> | <Literal>)
LTIME_TO_WSTRING (<Variablenname> | <Literal>)

Examples:

ST code

Result

TIME_TO_STRING(T#0MS);

'T#0MS'

LTIME_TO_WSTRING(T#0US);

"T#0US"