In Unix-like operating systems, time is represented as an offset in seconds from midnight (UTC) on January 1, 1970 (called the epoch). This type of representation, in addition to being compact, is independent of time zones, and is therefore directly comparable even between systems located in different geographical positions.
Note: The functions operate on Date / Time values with a high range but it is necessary to refer to the real time clock present on the system for the supported value.
SysDateGetS, get the system date on second
This function returns the system date in UTC expressed in seconds on a 32-bit variable. The range managed is from 00:00:00 on January 1st 1970 to 06:28:15 on February 7th 2106.
Function
CODESYS: Not available
LogicLab: eLLabXUnified12Lib
Description
The function returns a variable (UDINT) with the system date in UTC.
SysDateGetNs, get the system date on ns
This function returns the system date in UTC expressed in ns on a 64-bit variable. The managed range is from 00:00:00 on 1st January 1970 to 23:34: 33.709 on 21st July 2554.
Function
CODESYS: Not available
LogicLab: eLLabXUnified12Lib
Description
The function returns a variable (ULINT) with system date in UTC.
SysDateSetS, set the system date on second
This function sets the system date in UTC expressed in seconds on a 32-bit variable. The range managed is from 00:00:00 on January 1st 1970 to 06:28:15 on February 7th 2106.
Replaces "SysSetUTCDateTime"
Replaces the function SysSetUTCDateTime whose use is deprecated.
Function
CODESYS: Not available
LogicLab: eLLabXUnified12Lib
Description
UTCDateTime (UDINT) System date value in UTC expressed in seconds.
The function returns a variable (BOOL) FALSE: Execution error, TRUE: Ok execution.
Examples
How to use the examples.
In the following example, the value returned by the function is saved in a variable.
LogicLab (Ptp116, ST_DateTimeFunctions)
PROGRAM ST_DateTimeFunctions
VAR
i : UDINT; (* Auxiliary variable *)
DTime : DATE_AND_TIME; (* Date/Time *)
LDTime : LDATE_AND_TIME; (* Date/Time *)
LDTS : ARRAY[0..1] OF LDATETIMESTRUCT; (* Long Date/Time struct *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_DateTimeFunctions"
// *****************************************************************************
// Use of date functions.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// 32 BITS DATE FUNCTIONS
// -------------------------------------------------------------------------
// The "SysDateGetS" function returns a value in the range
// From 1970-01-01-00:00:00 to 2106-02-07-06:28:15
// After conversion in DATE_AND_TIME the range will be
// From 1970-01-01-00:00:00 to 2038-01-19-03:14:07
DTime:=TO_DATE_AND_TIME(SysDateGetS());
i:=SPLIT_DT(TO_DATE_AND_TIME(SysDateGetS()), ADR(LDTS[0].Year), ADR(LDTS[0].Month), ADR(LDTS[0].Day), ADR(LDTS[0].Hours), ADR(LDTS[0].Minutes), ADR(LDTS[0].Seconds));
// -------------------------------------------------------------------------
// 64 BITS DATE FUNCTIONS
// -------------------------------------------------------------------------
// The "SysDateGetNs" function returns a value in the range
// From 1970-01-01-00:00:00 to 2554-07-21-03:23:34:33.709
// After conversion in LDATE_AND_TIME the range will be
// From 1970-01-01-00:00:00 to 2262-04-11-23:47:16.854
LDTime:=TO_LDATE_AND_TIME(SysDateGetNs());
i:=SPLIT_LDT(TO_LDATE_AND_TIME(SysDateGetNs()), ADR(LDTS[1].Year), ADR(LDTS[1].Month), ADR(LDTS[1].Day), ADR(LDTS[1].Hours), ADR(LDTS[1].Minutes), ADR(LDTS[1].Seconds), ADR(LDTS[1].Milliseconds), ADR(LDTS[1].Microseconds), ADR(LDTS[1].Nanoseconds));
// [End of file]