DATE/DT_TO_<type>

This IEC operator converts from the data type DATE or DATE_AND_TIME (DT) to a different data type.

Syntax: <DATE data type>_TO_<data type>

TwinCAT saves the date internally in a DWORD in seconds since 1 January 1970. TwinCAT converts this value. With the data type STRING the result is the date constant.

DATE/DT_TO_<type> 1:

Information may be lost during type conversion from larger to smaller data types.

Samples:

ST code

Result

bVar := DATE_TO_BOOL(D#1970-01-01);

FALSE

nVar := DATE_TO_INT(D#1970-01-15);

29952

nVar := DT_TO_BYTE(DT#1970-01-15-05:05:05);

129

sVar := DT_TO_STRING(DT#1998-02-13-14:20);

'DT#1998-02-13-14:20:00'

FBD code

Result

DATE/DT_TO_<type> 2:

FALSE

DATE/DT_TO_<type> 3:

29952

DATE/DT_TO_<type> 4:

129

DATE/DT_TO_<type> 5:

'DT#1998-02-13-14:20:00'

See also: