TO_DATE block
Short summary
Name |
TO_DATE |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard as realized (see " Explicit conversion according to IEC-standard") |
Graphical interface |
|
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.
If the connected value is within the range of values overlapping for the data type of the input and for the result value DATE, the blocks returns this value. The conversion of the connected value is based on seconds, relative to the lower limit D#1970-01-01 of DATE ( 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:
LDATE_AND_TIME, DATE_AND_TIME
The data type LDATE_AND_TIME is currently not supported in logi.CAD 3. For the conversion of the data type DATE_AND_TIME, the block DT_TO_DATE is also available – this block is IEC-compliant.
Inputs, return value
|
Identifier |
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: |
– |
DATE |
|
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 respectively, before the block is executed. The output ENO of the block is set to value FALSE (or an equivalent), in case of
the data type TIME_OF_DAY.
the 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 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 ExampleToDate
VAR
result : DATE;
END_VAR
result := TO_DATE(IN := SINT#
12
);
Assert(result = D#
1970
-
01
-
01
);
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 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 > D#9999-12-31.
|
Lower limit |
Upper limit |
||
Literal for IN |
Return value |
Literal for IN |
Return value |
|
BOOL |
0 |
D#0001-01-01 |
1 |
D#0001-01-02 |
BYTE |
16#00 |
D#1970-01-01 |
16#FF |
D#1970-01-01 |
DATE |
D#1970-01-01 |
D#1970-01-01 |
D#9999-12-31 |
D#9999-12-31 |
DINT |
-2_147_483_648 to -2_147_472_001 |
D#1901-12-13 |
2_147_472_000 to 2_147_483_647 |
D#2038-01-19 |
DT |
DT#1970-01-01-00:00:00 |
D#1970-01-01 |
DT#9999-12-31-23:59:59 |
D#9999-12-31 |
DWORD |
16#0000_0000 to 16#0001_517F |
D#1970-01-01 |
16#FFFF_A500 to 16#FFFF_FFFF |
D#2106-02-07 |
INT |
-32_768 to -1 |
D#1969-12-31 |
0 to 32_767 |
D#1970-01-01 |
LINT |
-62_135_769_600 to -62_135_683_201 |
D#0001-01-01 |
253_402_214_400 to 253_402_300_799 |
D#9999-12-31 |
LREAL |
LREAL#-62_135_769_600.0 to LREAL#-62_135_683_201.0 |
D#0001-01-01 |
LREAL#253_402_214_400.0 to LREAL#253_402_300_799.0 |
D#9999-12-31 |
LWORD |
16#0000_0000_0000_0000 to 16#0000_0000_0001_517F |
D#1970-01-01 |
16#0000_003A_FFF2_F000 to 16#003A_FFF4_417F |
D#9999-12-31 |
REAL |
REAL#-62_135_769_087.0 to REAL#-62_135_683_072.0 |
D#0001-01-01 |
REAL#253_402_210_303.0 to REAL#253_402_300_799.0 |
D#9999-12-31 |
SINT |
-128 to -1 |
D#1969-12-31 |
0 to 127 |
D#1970-01-01 |
TIME |
T#-719_164d |
D#0001-01-01 |
T#2_932_896d |
D#9999-12-31 |
TOD |
TOD#00:00:00 |
D#0001-01-01 |
TOD#23:59:59.999_000_000 |
D#0001-01-01 |
UDINT |
0 to 86399 |
D#1970-01-01 |
4_294_944_000 to 4_294_967_295 |
D#2106-02-07 |
UINT |
0 |
D#1970-01-01 |
65_535 |
D#1970-01-01 |
ULINT |
0 to 86399 |
D#1970-01-01 |
253_402_214_400 to 253_402_300_799 |
D#9999-12-31 |
USINT |
0 |
D#1970-01-01 |
255 |
D#1970-01-01 |
WORD |
16#00 |
D#1970-01-01 |
16#FFFF |
D#1970-01-01 |