Date and time constants
32-bit dates 'DATE'
Use the DATE (D) keyword to specify dates.
Syntax:
<date keyword>#<year>-<month>-<day>
<date keyword> : DATE | date | D | d
<year> : 1970-2106
<month> : 1-12
<day> : 1-31
DATE literals are internally treated like the DWORD data type, which corresponds to an upper limit of DATE#2106-2-7.
Example:
PROGRAM MAIN
VAR
dStart : DATE := DATE#2018-8-8;
dEnd : DATE := D#2018-8-31;
dCompare : DATE := date#1996-05-06;
bInTime : BOOL;
dEarliest : DATE := d#1970-1-1; // = 0
dLatest : DATE := DATE#2106-2-7; // = 4294967295
END_VAR
IF dStart < dCompare THEN
IF dCompare < dEnd THEN
bInTime := TRUE;
END_IF;
END_IF
64-bit dates 'LDATE'
Use the LDATE (LD) keyword to specify dates.
Syntax:
<date keyword>#<year>-<month>-<day>
<date keyword> : LDATE | ldate | LD | ld
<year> : 1970-2554
<month> : 1-12
<day> : 1-31
LDATE literals are internally treated like the LWORD data type, which corresponds to an upper limit of DATE#2554-7-21.
Example:
PROGRAM MAIN
VAR
dStart : LDATE := LDATE#2018-8-8;
dEnd : LDATE := ldate#2018-8-31;
dCompare : LDATE := LD#1996-05-06;
bInTime : BOOL;
dEarliest : LDATE := ld#1970-1-1; // = 0
dLatest : LDATE := LDATE#2554-7-21;
END_VAR
IF dStart < dCompare THEN
IF dCompare < dEnd THEN
bInTime := TRUE;
END_IF;
END_IF
32-bit date and time specifications 'DATE_AND_TIME'
Use the DATE_AND_TIME (DT) keyword to specify date and time.
Syntax:
<date and time keyword>#<date and time value>
<date and time keyword> : DATE_AND_TIME | date_and_time | DT | dt
<date and time value> : <year>-<month>-<day>-<hour>:<minute>:<second>
<year> : 1970-2106
<month> : 1-12
<day> : 1-31
<hour> : 0-24
<minute> : 0-59
<second> : 0-59
DATE_AND_TIME literals are internally handled as DWORD data type. The time is processed in seconds and can therefore take values from January 1, 1970 00:00 to February 07, 2106 6:28:15.
Example:
PROGRAM MAIN
VAR
dtDate0 : DATE_AND_TIME := DATE_AND_TIME#1996-05-06-15:36:30;
dtDate1 : DATE_AND_TIME := DT#1972-03-29-00:00:00;
dtDate2 : DT := DT#2018-08-08-13:33:20.5;
dtEarliest : DATE_AND_TIME := DATE_AND_TIME#1979-1-1-00:00:00; // 0
dtLatest : DATE_AND_TIME := DATE_AND_TIME#2106-2-7-6:28:15; // 4294967295
END_VAR
64-bit date and time specifications 'LDATE_AND_TIME'
Use the LDATE_AND_TIME (LDT) keyword to specify date and time.
Syntax:
<date and time keyword>#<long date and time value>
<date and time keyword> : LDATE_AND_TIME | ldate_and_time | LDT | ldt
<date and time value> : <year>-<month>-<day>-<hour>:<minute>:<second>
<year> : 1970-2554
<month> : 1-12
<day> : 1-31
<hour> : 0-24
<minute> : 0-59
<second> : 0-59
LDATE_AND_TIME literals are internally handled as LWORD data type. The time is processed in seconds and can therefore have values from January 1, 1970 00:00 to July 21, 2554 23:59:59.999999999.
Sample:
PROGRAM MAIN
VAR
dtDate0 : LDATE_AND_TIME := LDATE_AND_TIME#1996-05-06-15:36:30;
dtDate1 : LDATE_AND_TIME := LDT#1972-03-29-00:00:00;
dtDate2 : LDT := LDT#2018-08-08-13:33:20.5;
dtEarliest : LDATE_AND_TIME := LDT#1979-1-1-00:00:00; // 0
dtLatest : LDATE_AND_TIME := LDT#2554-7-21-23:59:59;
END_VAR
32-bit dates 'TIME_OF_DAY
Use the TIME_OF_DAY (TOD) keyword to specify time.
Syntax:
<time keyword>#<time value>
<time keyword> : TIME_OF_DAY | time_of_day | TOD | tod
<time value> : <hour>:<minute>:<second>
<hour> : 0-23
<minute> : 0-59
<second> : 0.000-59.999
You can also specify fractions of a second in seconds. TIME_OF_DAY literals are internally treated as DWORD and thus the value is resolved in milliseconds.
Sample:
PROGRAM MAIN
VAR
tdClockTime0 : TIME_OF_DAY := TIME_OF_DAY#15:36:30.123;
tdClockTime1 : TOD := TOD#12:34:56.789;
tdEarliest : TIME_OF_DAY := TIME_OF_DAY#0:0:0.000;
tdLatest : TIME_OF_DAY := TIME_OF_DAY#23:59:59.999;
END_VAR
64-bit dates 'LTIME_OF_DAY
Use the keyword LTIME_OF_DAY (LTOD) to specify the time.
Syntax:
<time keyword>#<time value>
<time keyword> : LTIME_OF_DAY | ltime_of_day | LTOD | ltod
<time value> : <hour>:<minute>:<second>
<hour> : 0-23
<minute> : 0-59
<second> : 0.000-59.999999999
You can also specify fractions of a second in seconds. LTIME_OF_DAY literals are internally treated as LWORD, thus the value is resolved in nanoseconds.
Example:
PROGRAM MAIN
VAR
tdClockTime0 : LTIME_OF_DAY := LTIME_OF_DAY#15:36:30.123;
tdClockTime1 : LTOD := LTOD#12:34:56.7890123456;
tdEarliest : LTIME_OF_DAY := LTIME_OF_DAY#0:0:0.000;
tdLatest : LTIME_OF_DAY := LTIME_OF_DAY#23:59:59.999999999;
END_VAR
See also: