Topic: DMD0222

Managing the Date and Time in a Do-more Controller


Current Date and Time Stored as UTC Time

The current date and time in the Do-more controller is internally stored as a UTC (Coordinated Universal Time) value. The UTC value is the number of seconds that have elapsed since a particular point in time. Do-more controllers use the 1970 Epoch - which began at  00:00:00, 1 January 1970 - as that reference point in time. The current date and time ($LocalTime) for a given controller is rendered from the UTC time value by applying adjustments for the time zone, and for daylight savings time (if required).

 

There are three predefined locations in the controller that contain UTC-centric time values, they are:
 

  • $UTC - (DST21) - the current time in UTC form
     

  • $TimeZone - (DST384) - the number of minutes of adjustment for the current time zone
     

  • $LocalTime - (DST22) - the current date and time in UTC form, rendered from the UTC value after applying adjustments for the time zone and daylight savings time.

 

While it is true that storing timestamps in native UTC form can be very useful (they only consume a single DWord location), viewing the UTC values native form is not all that useful. The Data View has a display format called '1970 Epoch' which will display a UTC value in human-readable form (DD-MMM-YYYY Day Hour:Minute:Second).

 

In the Data View below, the first entry is $UTC in native format, the second is $UTC displayed in the 1970 Epoch format. At the end are similar entries for $LocalTime.

 


System and User Date/Time Structures

There are two predefined memory blocks of Date/Time structures, they are SDT0 - SDT7 (System Date/Time) which contain system generated date and time values, and UDT0 - UDT31 (User Date/Time) which the programmer can use in the ladder logic project to for runtime management of date and time and values.

 

 

Date/Time structures have the following members:
 

.Year - contains a 4-digit number representing the year
 

.Month - contains a value 1 to 12 representing the month (1 - January, 2 - February, ...12 - December)
 

.Day - contains a value from 1 to 31 representing the day of the month
 

.DayOfWeek - contains a value from 0 to 6 representing the day of the week (0 - Sunday, 1 - Monday ... 6 - Saturday)
 

.Hour - contains a value from 0 to 23 representing the hours
 

.Minute - contains a value from 0 to 59 representing the hours
 

.Second - contains a value from 0 to 59 representing the hours

 

There are three predefined System Date/Time structures:
 

$Now - (SDT0) - which contains the system-generated current date and time value, including adjustment for time zone and daylight savings time.
 

$SysShutdown - (SDT1) - contains the date and time when the controller was last powered OFF.
 

$SysStartup - (SDT2) - contains the date and time when the  controller was last powered ON.

 


Converting between UTC values and Date/Time Structures

Do-more controllers have two instructions that make converting UTC time values to Date/Time structures and vice versa very easy, they are:
 

Performing MATH-style operations on Date/time Structures

Setting the Clock at Runtime

  • NETTIME - SNTP Client - retrieves clock and calendar information from a time server using the SNTP protocol, calculate the local time, then set the controller's real-time clock to the newly calculated local time value.
     

  • SETTIME - Set PLC Date/Time - changes the PLC's internal clock calendar to the Date and Time specified in a User Date/Time structure or a System Date/Time Structure.

 


See Also:

 


Copyright © Host Engineering, Inc. ALL RIGHTS RESERVED