Get_CPU_DateTime
Overview
The Get_CPU_DateTime function block retrieves the current date and time from the PLC CPU real-time clock (RTC).
The returned values are provided as separate fields for month, day, year, hours, minutes, and seconds.
Month => (USINT)
Day => (USINT)
Year => (USINT)
Hours => (USINT)
Minutes => (USINT)
Seconds => (USINT)
Interface
Inputs
This function block has no inputs.
💡 RTC Source
The values returned by this function reflect the CPU real-time clock (RTC). The RTC is set at program download, using the PC’s date and time. It continues to run independently of the PLC program execution, and is maintained by a backup battery when the PLC is powered off.
Outputs
| Name | Type | Range / Units | Description |
|---|---|---|---|
| Month | USINT | 1 - 12 | The current month. |
| Day | USINT | 1 - 31 | The current day of the month. |
| Year | USINT | 0 - 255 | The current year. |
| Hours | USINT | 0 - 23 | The current hour. |
| Minutes | USINT | 0 - 59 | The current minute. |
| Seconds | USINT | 0 - 59 | The current second. |
Example:
PROGRAM PROG_Get_CPU_DateTime
VAR
CPU_Time : Get_CPU_DateTime;
Month : USINT;
Day : USINT;
Year : USINT;
Hours : USINT;
Minutes : USINT;
Seconds : USINT;
END_VAR
(* Read CPU date/time *)
CPU_Time();
(* Copy outputs to local variables (optional) *)
Month := CPU_Time.Month;
Day := CPU_Time.Day;
Year := CPU_Time.Year;
Hours := CPU_Time.Hours;
Minutes := CPU_Time.Minutes;
Seconds := CPU_Time.Seconds;
END_PROGRAM
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK task1_100ms(INTERVAL := T#100ms, PRIORITY := 1);
PROGRAM Prog_Instance_GetCPUDateTime WITH task1_100ms : PROG_Get_CPU_DateTime;
END_RESOURCE
END_CONFIGURATION