TO_DT block

Short summary

Name

TO_DT

→POU type

→function

Category

IEC-block, ConvertEnh, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard as realized (see " Explicit conversion according to IEC-standard")

Graphical interface

images/download/thumbnails/414781098/TO_DT-version-1-modificationdate-1534929739348-api-v2.png

Available since

version 1.65.0 (for logi.CAD 3)

Functionality

The blocks serves for explicitly converting the value connected to input IN into a value of data type DATE_AND_TIME (also identified as DT).

If the connected value is within the range of values overlapping for the data type of the input and for the result value DT, the blocks returns this value. The conversion of the connected value is based on seconds, relative to the lower limit DT#1970-01-01-00:00:00.000_000_000 of DATE_AND_TIME ( see under "Example for usage within ST-editor" and "Range of values for conversions" for lower and upper limits per data type).

Explicit conversion according to IEC-standard

The IEC-standard defines an explicit conversion of the following data types to DATE_AND_TIME:

LDATE_AND_TIME

This data type LDATE_AND_TIME is currently not supported in logi.CAD 3.

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, DATE_AND_TIME, DATE or TIME_OF_DAY

value to be converted

Return value:

DT


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

Internal error diagnostic for block

The block checks the data type of the value connected to input IN and the return value before the block is executed.
In case of data type LINT, ULINT, REAL or LREAL and an expected return value < DT#0001-01-01-00:00:00 or > DT#9999-12-31-23:59:59, the output ENO of the block is set to value FALSE (or an equivalent) and the return value is set to the appropriate minimum or maximum value (see under "Range of values for conversions").

Example for usage within ST-editor

The calculated values are evaluated by using the Assert block .

FUNCTION_BLOCK ExampleToDt
VAR
result : DATE_AND_TIME;
END_VAR
result := TO_DT(IN := SINT#12);
Assert(result = DT#1970-01-01-00:00:12);
END_FUNCTION_BLOCK

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.

Range of values for conversions

The range of values for the conversions is determined by the lower and upper limit of the data types. This lower and upper limit per data type is listed under "Supported data types (in ST)".
Keep the following in mind: The lower limit for DATE or DATE_AND_TIME is valid for literals. Due to calculations or conversions, logi.CAD 3 is able to process and displays values down to DATE#0001-01-01 and DT#0001-01-01-00:00:00.000_000_000 respectively.

The following table lists the literals for IN for that the block returns the smallest possible return value resp. the largest possible return value (relating to the data type for IN) that can be processed on all target systems. Depending on your target system it might be possible to use literals resulting in a return value > DT#9999-12-31-23:59:59.


Data type
for IN

Lower limit

Upper limit

Literal for IN

Return value

Literal for IN

Return value

BOOL

0

DT#0001-01-01-00:00:00

1

DT#0001-01-01-00:00:01

BYTE

16#00

DT#1970-01-01:00:00:00

16#FF

DT#1970-01-01-00:04:15

DATE

D#1970-01-01

DT#1970-01-01-00:00:00

D#9999-12-31

DT#9999-12-31-00:00:00

DINT

-2_147_483_648

DT#1901-12-13-20:45:52

2_147_483_647

DT#2038-01-19-03:14:07

DT

DT#1970-01-01-00:00:00

DT#1970-01-01-00:00:00

DT#9999-12-31-23:59:59

DT#9999-12-31-23:59:59

DWORD

16#0000_0000

DT#1970-01-01-00:00:00

16#FFFF_FFFF

DT#2106-02-07-06:28:15

INT

-32_768

DT#1969-12-31-14:53:52

32_767

DT#1970-01-01-09:06:07

LINT

-62_135_769_600

DT#0001-01-01-00:00:00

253_402_300_799

DT#9999-12-31-23:59:59

LREAL

LREAL#-62_135_769_600.0

DT#0001-01-01-00:00:00

LREAL#253_402_300_799.0

DT#9999-12-31-23:59:59

LWORD

16#0000_0000_0000_0000

DT#1970-01-01-00:00:00

16#003A_FFF4_417F

DT#9999-12-31-23:59:59

REAL

REAL#-62_135_769_000.0

DT#0001-01-01-00:42:40 (1)

REAL#253_402_300_799.0

DT#9999-12-31-23:53:36 (1)

SINT

-128

DT#1969-12-31-23:57:52

127

DT#1970-01-01-00:02:07

TIME

T#-719_164d

DT#0001-01-01-00:00:00

T#2_932_896d23h59m59s

DT#9999-12-31-23:59:59

TOD

TOD#00:00:00

DT#1970-01-01-00:00:00

TOD#23:59:59.999_000_000

DT#1970-01-01-23:59:59.999_000

UDINT

0

DT#1970-01-01-00:00:00

4_294_967_295

DT#2106-02-07-06:28:15

UINT

0

DT#1970-01-01-00:00:00

65_535

DT#1970-01-01-18:12:15

ULINT

0

DT#1970-01-01-00:00:00

253_402_300_799

DT#9999-12-31-23:59:59

USINT

0

DT#1970-01-01-00:00:00

255

DT#1970-01-01-00:04:15

WORD

16#00

DT#1970-01-01-00:00:00

16#FFFF

DT#1970-01-01-18:12:15

(1) This return value is valid for the built-in PLC under Windows. Depending on your target system, the return value might differ regarding the TIME fraction due to the REAL precision.