Constants: Date and Time
32-bit date specification: DATE
Use the DATE
keyword (D
) to specify a date.
Syntax
<date keyword>#<year>-<month>-<day> <date keyword> : DATE | date | D | d <year> : 1970-2106 <month> : 1-12 <day> : 1-31
DATE
literals are treated internally as data type DWORD
, which corresponds to an upper limit of DATE#2106-2-7
.
PROGRAM PRG_Date VAR dateStart : DATE := DATE#2018-8-8; dateEnd : DATE := D#2018-8-31; dateCompare: DATE := date#1996-05-06; xIsDuringTheTime: BOOL; dateEarliest : DATE := d#1970-1-1; // = 0 dateLatest : DATE := DATE#2106-2-7; // = 4294967295 END_VAR IF dateStart < dateCompare THEN IF dateCompare < dateEnd THEN xIsDuringTheTime := TRUE; END_IF; END_IF
64-bit date specification: LDATE
Use the LDATE
keyword (LD
) to specify a date.
Syntax
<date keyword>#<year>-<month>-<day> <date keyword> : LDATE | ldate | LD | ld <year> : 1677-2262 <month> : 1-12 <day> : 1-31
LDATE
literals are treated internally as data type LWORD
, which corresponds to an upper limit of DATE#2554-7-21
.
PROGRAM PRG_Ldate VAR ldateStart : LDATE := LDATE#2018-8-8; ldateEnd : LDATE := ldate#2018-8-31; ldateCompare: LDATE := LD#1996-05-06; xIsDuringTheTime: BOOL; ldateEarliest : LDATE := ld#1677-9-22; // = 0 ldateLatest : LDATE := LDATE#2262-4-11; // = 16#7FFFB21D1DB10000 lwValue: LWORD; END_VAR IF ldateStart < ldateCompare THEN IF ldateCompare < ldateEnd THEN xIsDuringTheTime := TRUE; END_IF; END_IF lwValue := LDATE_TO_LWORD(ldateCompare);
32-bit date and time specification: DATE_AND_TIME
Use the DATE_AND_TIME
keyword (DT
) to specify a 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 treated internally as data type DWORD
. The time is processed in seconds and as a result can take on values from January 1, 1970 00:00 to February 7, 2106 06:28:15.
PROGRAM PLC_PRG VAR dtDate : DATE_AND_TIME := DATE_AND_TIME#1996-05-06-15:36:30; dtDate1: DATE_AND_TIME := DT#1972-03-29-00:00:00; dtDate2: DATE_AND_TIME := DT#2018-08-08-13:33:20.5; dtEarliest : DATE_AND_TIME := DATE_AND_TIME#1970-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 specification: LDATE_AND_TIME
Use the LDATE_AND_TIME
keyword (LDT
) to specify a 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> : 1677-2262 <month> : 1-12 <day> : 1-31 <hour> : 0-24 <minute> : 0-59 <second> : 0-59
LDATE_AND_TIME#2262-4-10-23:59:59.99999999
LDATE_AND_TIME
literals are treated internally as data type LWORD
. The time is processed in nanoseconds and can therefore have values from September 21, 1677 00:12:43.145224192 to April 11, 2262 23:47:16.854775807.
PROGRAM PLC_PRG VAR ldtDate : LDATE_AND_TIME := LDATE_AND_TIME#1996-05-06-15:36:30; ldtDate1: LDATE_AND_TIME := LDT#1972-03-29-00:00:00; ldtDate2: LDATE_AND_TIME := LDT#2018-08-08-13:33:20.5; dtEarliest : LDT := LDT#1677-9-21-0:12:43.145224192; // 0 dtLatest : LDT := LDT#2262-4-11-23:47:16.854775807; // = 16#7FFFFFFFFFFFFFFF END_VAR
32-bit time specification: TIME_OF_DAY
Use the TIME_OF_DAY
keyword (TOD
) to specify a 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. TIME_OF_DAY
literals are treated internally as DWORD
and the value is resolved in milliseconds.
PROGRAM POU VAR todClockTime : TIME_OF_DAY := TIME_OF_DAY#15:36:30.123; todEarliest : TIME_OF_DAY := TIME_OF_DAY#0:0:0.000; todLatest : TOD := TOD#23:59:59.999; END_VAR
64-bit time specification: LTIME_OF_DAY
Use the LTIME_OF_DAY
keyword (LTOD
) to specify a 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. LTIME_OF_DAY
literals are treated internally as LWORD
and the value is resolved in nanoseconds.
PROGRAM POU VAR ltodClockTime : LTIME_OF_DAY := TIME_OF_DAY#15:36:30.123456789; todEarliest : TIME_OF_DAY := TIME_OF_DAY#0:0:0; todLatest : TOD := TOD#23:59:59.999999999; END_VAR
For more information, see: Data type: DATE