Tag Archives: Siemens date and time format

Time and date data format in SIEMENS S7-300/400 series PLC

Data types are split into basic data types and complex data types. Data formats for time and date have both basic and complex data types.

1. Time of Day and wherein DATE belongs to the basic data types

1.1 DATE is a 16-bit data type in IEC format with a resolution of 1 day;
The format is D#1990-01-01~D#2168-12-31 or DATE#1990-1-1~DATE#2168-12-31;
It can be translated into and from INT type data. D#1990-1-1 corresponds to 1, and for every 1 increase in INT data, the DATE data value is increased by 1 day.

1.2 Time of Day is a 32-bit 24-hour time format with a resolution of 1ms
The format is TOD#00:00:00.000~TOD#23:59:59.999;
It can be translated into and from DINT type data. TOD#00:00:00.000 corresponds to 1, and Dever increases by 1 and the Time of Day time value increases by 1ms.

2. DATE_AND_TIME is a data type match
DATE_AND_TIME includes 8 bytes, the description of each byte is shown in the figure below;
The format is DT#1990-1-1-0:0:0.0 to DT#2089-12-31-23:59:59.999;

How to set multiple dates for Siemens system time

There comes a time setting in the properties of the CPU of Siemens S7-1200 system. When we use it, if there is a relatively high requirement for time, we must give attention to setting the correct parameters, otherwise it will be incorrect.
Pay heed to the choice of time zone. The picture above shows UTC time, ie GMT time, time standard time. If it is Beijing time, please choose UTC+8, 8 hours earlier. If there is daylight saving time, please enable the daylight saving time option and China has cancelled daylight saving time.

After this setting, the CPU goes online and can synchronize the module time to the time the PG/PC. Otherwise it is the factory default date of the PLC.

We can see whether the time and time in the CPU are set correctly by reading the local and system time instructions in the date and time in the extended instruction.

The two instructions are: RD_LOC_T (read local time, ie with time difference) and RD_SYS_T (read system time, ie UTC time)

Siemens PLC data type _ date and time

Date and time data types include:
DATE, date;
TIME_OF_DAY, time (the current time is a few minutes and a few seconds);
LTIME_OF_DAY, time (the current time is a few minutes and a few seconds, a few milliseconds);
DATE_AND_TIME, date + time, BCD code transferred, to milliseconds;
LDT, date + time, unsigned integer, to nanoseconds;
DTL, date + time, structure, to nanoseconds.

LDT and DTL actually express the same content, but the way they are expressed is different.

The range and precision of LDT and DTL are the same. DTL uses a structure to express it. There is also an expression of the day of the week, which is calculated according to the year, month and day.

Siemens date and time format

    Siemens S7-200/200smart series

This series of read and write instructions is very simple, you can use an instruction and fill in the address, the data has a fixed format.

    S7-300/400, S1200, S1500 series

This series of PLC date and time data types mainly includes; 1 date (date), 2 day time (Time_Of_ Day), 3 long time LTOD (LTime_Of_Day), 4 date time DT (Date_And_Time), 5 date long time LDT ( Date_And_LTime), 6 long date and time DTL.

   For Siemens S7-300/400, S1200, S1500 these data types are not universal.

We need to figure out these date formats

(1) Date DATE

Data type the data as an unsigned integer. The notation contains the year, month and day.

The data type DATE operand is located in hexadecimal form, corresponding to the date value (16#0000) since 01-01-1990. The contents of the variable are shown in integer format by the number of days from January 1, 1990. The constant format is D# before the date. For example, the date specified by D#2168 – 12-31 is December 31, 2168, and the content of the corresponding variable is W#16#FF62.

(2) Day time (Time_Of_ Day)

TOD (TIME_OF_DAY) data type occupies a double word and stores the number of milliseconds from 0:00 h of the day, which is an unsigned integer. The constant indicates that the format is TOD# before the time.

(3) Long time LTOD (LTime_Of_Day)

Long-day LTOD (LTime_Of_Day) data type occupies 2 double words and stores the number of nanoseconds from 0:00 of the day, which is an unsigned integer. Nanosecond data are only available in the S1500 series.

(4) Date time DT ( Date_And_Time)

The daytime DT (Date_And_Time) data type stores date and time information in the format BCD.

(5) Date long LDT (Date_And_LTime)

The date long LDT (Date_And_LTime) data type stores date and time information (in nanoseconds) since 0:00 on January 1, 1970.

(6) Long date and time DTL

The extended date time (DTL) data type has an operand length of 12 bytes and stores date and time information in a predefined structure.

The structure of a DTL data type has several parts, each of which contains different data types and ranges of values. The data type of the specified value must match the data type of the corresponding element. Table 5-18 shows in the structural components of the DTL data type.