Operator ‘DATE_TO/DT_TO’¶
This IEC operator is used for converting the DATE and DATE_AND_TIME data types into another data type.
<DATE data type>_TO_<data type>
Internally, CODESYS saves the date to a DWORD (in seconds since 01 January 1970). CODESYS converts this value.
For the STRING data type, the result is the date constant.
Attention
Information can be lost when converting from larger data types to smaller data types.
Examples
| ST Code | Result |
|---|---|
b := DATE_TO_BOOL(D#1970-01-01); |
FALSE |
i := DATE_TO_INT(D#1970-01-15); |
29952 |
i := DATE_TO_BYTE(DT#1970-01-15-05:05:05); |
129 |
str := DT_TO_STRING(DT#1998-02-13-14:20); |
DT#1998-02-13-14:20 |
| FBD Code | Result |
|---|---|
FALSE |
|
29952 |
|
129 |
|
DT#1998-02-13-14:20 |