5 date_to / dt_to, 6 string_to, 7 trunc – Lenze DDS v2.3 User Manual
Page 296: Date_to / dt_to, String_to, Trunc, Drive plc developer studio

Drive PLC Developer Studio
IEC 61131-3 Standard functions
14-4
l
DDS EN 2.3
14.1.5
DATE_TO / DT_TO
Converting from type DATE or DATE_AND_TIME to another type
Internally, the date is saved in a DWORD in seconds since the 1st of January 1970. This value is
converted.
•
With type STRING, the result is a date constant.
•
Conversion from higher- to lower-order types may result in information loss.
Examples
IL
LD D#1970-01-01
DATE_TO_BOOL
ST b
LD D#1970-01-15
DATE_TO_INT
ST i
LD DT#1970-01-15-05:05:05
DT_TO_BYTE
ST byt
LD DT#1998-02-13-14:20
DT_TO_STRING
ST str
ST
b:=DATE_TO_BOOL(D#1970-01-01);
i:=DATE_TO_INT(D#1970-01-15);
byt:=DT_TO_BYTE(DT#1970-01-15-05:05:05);
str:=DT_TO_STRING(DT#1998-02-13-14:20);
(* b=FALSE *)
(* i=29952 *)
(* byt=129 *)
(* str=
’DT#1998-02-13-14:20’ *)
FBD
14.1.6
STRING_TO
Converting STRING into another type
The operand of type STRING must have a valid target type value as otherwise
the result will be 0.
Examples
IL
LD ’TRUE’
STRING_TO_BOOL
ST b
LD ’123’
STRING_TO_WORD
ST w
LD ’t#127ms’
STRING_TO_TIME
ST t
ST
b:=STRING_TO_BOOL(’TRUE’);
w:=STRING_TO_WORD(’123’);
t:=STRING_TO_TIME(’T#127ms’);
(* b=TRUE *)
(* w=123 *)
(* t=T#127ms *)
14.1.7
TRUNC
Converting from REAL to type INT
•
Conversion uses the integer component of the floating-point number.
•
Conversion from higher- to lower-order types may result in information loss.
Examples
IL
ST
LD 1.9
TRUNC
ST i (* i=1 *)
LD -1.4
TRUNC
ST i (* i=-1 *)
i:=TRUNC(1.9);
i:=TRUNC(-1.4);
Show/Hide Bookmarks