Converting BCD Timestamp Formats to S7 DATE_AND_TIME in S7-410H and PCS 7 V9.0
To convert individual Binary Coded Decimal (BCD) timestamp bytes into a standard S7 DATE_AND_TIME (DT) structure in SIMATIC PCS 7 V9.0, no mathematical BCD-to-integer decoding is necessary because the S7 DATE_AND_TIME data type is natively stored in BCD format. An S7 DATE_AND_TIME variable consists of exactly 8 consecutive bytes: Byte 0 (Year 00-99), Byte 1 (Month 01-12), Byte 2 (Day 01-31), Byte 3 (Hour 00-23), Byte 4 (Minute 00-59), Byte 5 (Second 00-59), Byte 6 (Milliseconds MSB), and Byte 7 (Milliseconds LSB + Day of Week). To combine discrete BCD bytes into a unified DT variable, map the incoming bytes directly into an 8-byte global DB or SCL structure using byte MOVE operations or an SCL AT-overlay construct.
Table of Contents
- Executive Summary
- Architecture and Fundamental Mechanics
- Step-by-Step Implementation Procedure
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Executive Summary
In high-accuracy Sequence of Events (SOE) applications with ET 200SP HA time-stamped digital inputs or third-party serial power meters, field hardware frequently delivers event timestamps as individual BCD-encoded byte streams. Automation engineers implementing custom timestamp logging in PCS 7 V9.0 often attempt complex mathematical conversions (multiplying tens by 10 and adding units) to assemble S7 timestamps. However, the S7-400 / CPU 410-5H operating system fundamentally defines the DATE_AND_TIME primitive as an 8-byte packed BCD structure. This guide explains the exact internal bit layout of DATE_AND_TIME, demonstrates the most efficient SCL assembly pattern, and outlines best practices for routing timestamps to WinCC Alarm Logging.
Architecture and Fundamental Mechanics
Internal Structure of S7 DATE_AND_TIME (DT)
In SIMATIC S7-400 and CPU 410-5H architectures, the DATE_AND_TIME data type occupies 8 consecutive bytes in memory, formatted as follows:
+-------------------------------------------------------------------------+
| S7 DATE_AND_TIME (8 Bytes / 64 Bits) |
+-------------------------------------------------------------------------+
| Byte | Field | Format | Valid Range | Example (2026-10-14 23:00) |
|------|--------------|--------|-------------|----------------------------|
| 0 | Year | BCD | 00 - 99 | B#16#26 (Year 2026) |
| 1 | Month | BCD | 01 - 12 | B#16#10 (October) |
| 2 | Day | BCD | 01 - 31 | B#16#14 (14th) |
| 3 | Hour | BCD | 00 - 23 | B#16#23 (11 PM) |
| 4 | Minute | BCD | 00 - 59 | B#16#00 (00 minutes) |
| 5 | Second | BCD | 00 - 59 | B#16#15 (15 seconds) |
| 6 | Millisec MSB | BCD | 00 - 99 | B#16#02 (200 ms) |
| 7 | Millisec LSB | BCD | Bit 4-7: BCD| B#16#51 (50 ms + Sun=1) |
| | Day of Week | BIN | Bit 0-3: 1-7| (1=Sun, 2=Mon... 7=Sat) |
+-------------------------------------------------------------------------+
Direct Byte Mapping Mechanics
Because the incoming field data is already in BCD format, performing an arithmetic conversion to integer and then calling Step 7 conversion functions (such as FC3 D_TOD_DT) is computationally wasteful and introduces conversion overhead. Instead, by writing the raw BCD bytes directly into the 8 memory addresses allocated to a DATE_AND_TIME variable, the S7 CPU instantly interprets the bytes as a valid timestamp.
Step-by-Step Implementation Procedure
Step 1: Create a Shared Data Block for Timestamp Construction
- In SIMATIC Manager, open the S7 Program block container.
- Create a new Data Block:
DB150. - Open
DB150in the DB Editor and declare the variables:
-Raw_Bytes: Array [0..7] of BYTE
-Event_DT: DATE_AND_TIME - Alternatively, declare a user-defined type (UDT) matching the 8-byte structure.
Step 2: Implement Direct SCL Conversion Logic
- In the S7 SCL editor, create a dedicated function block:
FB1150(BCD_To_DT_Converter). - Declare input parameters for each BCD byte:
In_Year,In_Month,In_Day,In_Hour,In_Min,In_Sec,In_MS_High,In_MS_Low. - Use an SCL
AToverlay to construct theDATE_AND_TIMEvariable without arithmetic conversion:
```scl
FUNCTION_BLOCK FB1150
VAR_INPUT
In_Year : BYTE; // BCD format e.g. 16#26
In_Month : BYTE; // BCD format e.g. 16#10
In_Day : BYTE; // BCD format e.g. 16#14
In_Hour : BYTE; // BCD format e.g. 16#23
In_Min : BYTE; // BCD format e.g. 16#00
In_Sec : BYTE; // BCD format e.g. 16#15
END_VAR
VAR_OUTPUT
Out_DT : DATE_AND_TIME;
END_VAR
VAR
DT_Structure : ARRAY[0..7] OF BYTE;
DT_Overlay AT DT_Structure : DATE_AND_TIME;
END_VAR
BEGIN
DT_Structure[0] := In_Year;
DT_Structure[1] := In_Month;
DT_Structure[2] := In_Day;
DT_Structure[3] := In_Hour;
DT_Structure[4] := In_Min;
DT_Structure[5] := In_Sec;
DT_Structure[6] := 16#00; // Milliseconds high
DT_Structure[7] := 16#01; // Milliseconds low + Sunday
Out_DT := DT_Overlay;
END_FUNCTION_BLOCK
```
Step 3: Integrate and Connect in CFC
- Compile the SCL block into the S7 Program.
- In CFC, drag
FB1150into the processing chart. - Connect the BCD byte outputs from your communication or channel driver blocks into the corresponding inputs of
FB1150. - Route
Out_DTto downstream recording blocks, sequence totalizers, or Alarm_8P associated values. - Compile CFC via Changes Only and download to the AS.
Verification
- Variable Table (VAT) Monitor: Create a VAT in SIMATIC Manager. Add the output address of
Out_DTand select display formatDATE_AND_TIME. Confirm that the timestamp displays human-readable date and time (e.g.,DT#2026-10-14-23:00:15.000). - Plausibility Check: Test edge cases such as month transitions (e.g., month =
16#12to16#01) and leap years to confirm the CPU evaluates the reconstructed DT cleanly without generating area-length or data-type faults in the diagnostic buffer. - WinCC Alarm Verification: Route the DT value to an alarm message block and verify that WinCC Alarm Logging displays the correct historical timestamp in the message list.
Limitations and Operational Precautions
- Century Representation: S7
DATE_AND_TIMEstores years 90–99 as 1990–1999, and years 00–89 as 2000–2089. Verify that field devices follow this standard two-digit convention. - Invalid BCD Trapping: If field hardware transmits an invalid BCD byte (such as
16#0Aor16#FF), standard S7 blocks handlingDATE_AND_TIMEwill trigger an operating system error. Always filter incoming bytes with a nibble mask (Byte AND 16#0F <= 9) to ensure BCD plausibility.
Engineer FAQ
Why does DATE_AND_TIME not require BCD-to-integer conversion?
Because S7 DATE_AND_TIME is internally stored in packed BCD format; discrete BCD bytes match the memory representation directly.
How many bytes does DATE_AND_TIME occupy?
Exactly 8 bytes (64 bits) in S7-300, S7-400, and CPU 410-5H memory.
What does Byte 7 of DATE_AND_TIME contain?
The upper 4 bits contain the least significant digit of milliseconds; the lower 4 bits contain the day of the week (1 = Sunday, 7 = Saturday).
Can I move BCD bytes into a DB using standard ladder (LAD)?
Yes, you can use 8 consecutive MOVE instructions transferring each byte to the respective byte address of the DT variable.
How do I unpack a DATE_AND_TIME into BCD bytes?
Use the reverse process: read the 8 individual byte offsets of the DATE_AND_TIME variable in SCL or STL.
What happens if an invalid BCD digit (e.g. 16#1F) is loaded?
Standard Step 7 time functions will fail or report an invalid date, and WinCC may display a default 1970 timestamp.
Does ET 200SP HA time stamping require manual BCD conversion?
No. Standard PCS 7 time-stamping driver blocks (Pcs7DiIT) handle ET 200SP HA 1 ms SOE timestamps automatically without user conversion.
Can S7 DATE_AND_TIME represent microseconds?
Standard S7 DT has a resolution of 1 millisecond. Microsecond time stamping uses specialized 10-byte time structures in ET 200SP HA.
What SCL instruction overlays different data types?
The AT keyword allows declaring a variable view over an existing memory area with a different data type.
Is SFC1 (READ_CLK) output formatted in BCD?
Yes, the system function SFC1 READ_CLK outputs system time directly in standard S7 DATE_AND_TIME BCD format.
Technical References
- SIMATIC S7-400 / CPU 410-5H System and Standard Functions Reference Manual
- SIMATIC S7-SCL V5.6 for S7-300/400 Programming Manual - Section Data Types
- Siemens Industry Online Support (SIOS) Entry ID 109780813: PCS 7 High-Precision Time Stamping Guide
- SIMATIC Step 7 V5.6 Format of the Data Type DATE_AND_TIME
Related Articles
- Implementing GPS and NTP Master Time Synchronization in PCS 7 Following SICLOCK Discontinuation
- Understanding APL Structured Data Types and Eliminating Data Type Conflicts in PCS 7 CFC
- Why Blocks in CFC Charts Are Called by OB35 - Execution Cycle Fundamentals in PCS 7
Related Tags
- DATE_AND_TIME
- BCD Conversion
- S7-410H
- SCL
- Time Stamping
- ET 200SP HA
- CFC Programming