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.
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 |
---|---|
FALSE | |
29952 | |
129 | |
'DT#1998-02-13-14:20:00' |
See also:
- Data types > Date and time data types