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
../_images/a72e631dd06e3192c0a8640e0015bae4 FALSE
../_images/2e779862d0736654c0a8640e00e33429 29952
../_images/01ae6320d0703adfc0a8640e002a67d1 129
../_images/aabddfccd076c5c6c0a8640e010a2bbc DT#1998-02-13-14:20