# SIEMENS Driver DATE\_AND\_TIME values

**URL:** <https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198>\
**Category:** Ignition\
**Created:** [September 26, 2012, 4:53pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198 "2012-09-26T16:53:51Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [October 5, 2020, 4:16pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/22 "2020-10-05T16:16:03Z")

</div>

@chi, I was trying to use your piece of code to read the time but can’t seem to understand exactly !

So, When I get the DATE and TIME in millis, at this point of time they are 11235 and 43640750 respectively. Now, from what you have., I understand that you want to shift binary of DATE to left by 32 bits to get the millis of date and then add millis of time into it. However, when I shift 32 bits left, my value is way too big (approx 188,535,312,519). Now, that value goes into the tag change event script and executed with binary. But, what comes out is nowhere close to current time.

Is there any reference to understand the DATETIME and binary conversion ?

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [October 6, 2020, 7:52am UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/23 "2020-10-06T07:52:21Z")

</div>

This thread is about a special datatype in legacy Siemens plcs. Look at the first post for a description of that type.  
Where did you get the values 11235 and 43640750 from? They don’t seem to be a date/time format i recognize.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [October 6, 2020, 12:34pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/24 "2020-10-06T12:34:51Z")

</div>

From the original question I understand that the requirement is to read (and write) time to PLC. The PLC I am using is S7-300 with Simatic Manager.

As per the picture below, I have created DB tags to store both TOD(Time\_Of\_Day) and DATE(Which both seems to be in millisecond format). Now, I am trying to read this in Ignition by creating 2 different tags and combining them with expression but, it doesn’t seem to work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aa89b5daf971463e9752be46b1957cb4a277ed21.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c795428fc5908d4b55e8134490a4b3089d952964.png)

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [October 6, 2020, 1:48pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/25 "2020-10-06T13:48:53Z")

</div>

Check the datatypes in the Siemens manuals. The original question in this thread is about the DATE\_AND\_TIME type.  
You are using TOD, a 32 bit unsigned integer with milliseconds since midnight. DATE is 16 bit unsigned integer with days since 1990-01-01.  
To convert it to a java time (milliseconds since 1970-01-01) you have to do some math (untested!):

```auto
631152000000+(DATE*24*60*60*1000)+TOD
# 631152000000 = milliseconds from 1970-01-01 to 1990-01-01

```

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [November 3, 2021, 2:56pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/26 "2021-11-03T14:56:18Z")

</div>

I am running into similar issues trying to get this data. Hoping the aforementioned tag change expression will end up working.

I also created a formal feature request for this since it seems like this should be something that exists.

> **[Siemens DTL datatype support | Voters | Inductive Automation](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/siemens-dtl-datatype-support)**

---

<div class="post-metadata">

**Author:** ![Dan\_Winchester](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Dan\_Winchester](https://forum.inductiveautomation.com/u/Dan_Winchester)\
**Post date:** [April 14, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/27 "2022-04-14T19:18:22Z")

</div>

Has there been any traction with converting the DATE \_AND\_TIME bytes to a human readable datetime string?

---

<div class="post-metadata">

**Author:** ![Dan\_Winchester](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Dan\_Winchester](https://forum.inductiveautomation.com/u/Dan_Winchester)\
**Post date:** [April 21, 2022, 7:50pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/28 "2022-04-21T19:50:07Z")

</div>

After working with Customer Service, we came up with the following expression to use:

“20” + toHex({[.]BASIC\_DATE\_AND\_TIME[0]}) + “-” + //Year, assuming in 21st century  
numberFormat(toHex({[.]BASIC\_DATE\_AND\_TIME[1]}), “00”) + “-” + //Month  
numberFormat(toHex({[.]BASIC\_DATE\_AND\_TIME[2]}), “00”) + “-” + //Day  
numberFormat(toHex({[.]BASIC\_DATE\_AND\_TIME[3]}), “00”) + “:” + //Hours  
numberFormat(toHex({[.]BASIC\_DATE\_AND\_TIME[4]}), “00”) + “:” + //Minutes  
numberFormat(toHex({[.]BASIC\_DATE\_AND\_TIME[5]}), “00”) + “:” + //Seconds  
numberFormat(fromBinary(left(numberFormat(toBinary({[.]BASIC\_DATE\_AND\_TIME[6]} + {[.]BASIC\_DATE\_AND\_TIME[7]}), “0000000000000000”), 12)), “000”) + " " + //Milliseconds, it includes the first 4 bits of byte 7  
case( //Day of the week, last 4 bits of byte 7  
right(numberFormat(toBinary({[.]BASIC\_DATE\_AND\_TIME[7]}), “00000000”), 4),  
“0000”, “Sunday”,  
“0001”, “Monday”,  
“0010”, “Tueday”,  
“0011”, “Wednesday”,  
“0100”, “Thursday”,  
“0101”, “Friday”,  
“0111”, “Saturday”,  
“Error - No Day Found”)

This worked to translate the old Siemens Date\_And\_Time data type to a string.

---

<div class="post-metadata">

**Author:** ![Michael\_Johannsen](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Michael\_Johannsen](https://forum.inductiveautomation.com/u/Michael_Johannsen)\
**Post date:** [March 18, 2024, 1:03pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/29 "2024-03-18T13:03:08Z")

</div>

Hi, I came across this in the manual. It seems that you can get the date\_and\_Time format via the Siemens driver.

But a guess the only applies for the driver and not when you are using the OPC server interface in the Siemens PLC to access the tags?  
Or am I'm missing something!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/2/024dc91a269613f1748491e813eb83153892f419.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 18, 2024, 1:04pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/30 "2024-03-18T13:04:28Z")

</div>

Not missing anything, that's correct.

---

<div class="post-metadata">

**Author:** ![Michael\_Johannsen](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Michael\_Johannsen](https://forum.inductiveautomation.com/u/Michael_Johannsen)\
**Post date:** [March 18, 2024, 1:10pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/31 "2024-03-18T13:10:30Z")

</div>

Tanks.  
Then I just have to do some PLC magic

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 18, 2024, 1:13pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/32 "2024-03-18T13:13:05Z")

</div>

There are one or two of the date/time types that are available over OPC UA with no fuss. I forget which ones... I can check in a bit.

edit: use LDT in the PLC, it gets exposed via the Siemens OPC UA Server as an OPC UA DateTime value.

---

<div class="post-metadata">

**Author:** ![Michael\_Johannsen](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@Michael\_Johannsen](https://forum.inductiveautomation.com/u/Michael_Johannsen)\
**Post date:** [March 18, 2024, 1:35pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/33 "2024-03-18T13:35:49Z")

</div>

That's way more easy.  
Thank you

---

<div class="post-metadata">

**Author:** ![Andrew\_Buldyzhov](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrew_buldyzhov/32/74246_2.png) [@Andrew\_Buldyzhov](https://forum.inductiveautomation.com/u/Andrew_Buldyzhov)\
**Post date:** [September 24, 2025, 10:24am UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/34 "2025-09-24T10:24:03Z")

</div>

Here’s my solution which looks simpler, more user-friendly, and probably works faster too.

I have created a UDT structure with such tags:

| Tag name | Tag type | Data type |
| --- | --- | --- |
| DT\_byte\_array | OPC Tag | Short Array |
| Year\_raw | Expression Tag | Short |
| Year | Expression Tag | Short |
| Month | Expression Tag | Short |
| … | … | … |
| DateTime | Expression Tag | DateTime |

DT\_byte\_array points to an OPC tag of Byte Array type, but it has to be Short Array in Ignition to avoid overflow during BCD conversion.

Here’s the expression for Year\_raw:

```python
({[.]DT_byte_array[0]} >> 4) * 10 + // the left 4 bits of BCD number 
({[.]DT_byte_array[0]} & 0x0F) // the right 4 bits of BCD number

```

The expression for Year:

```python
if( {[.]Year_raw} >= 90, {[.]Year_raw} + 1900, {[.]Year_raw} + 2000 )  

```

For Month, Day, Hour, Minute, and Second, the expressions are similar, with the corresponding byte index in the array. Here’s the expression for Second:

```python
({[.]DT_byte_array[5]} >> 4) * 10 + // the left 4 bits of BCD number 
({[.]DT_byte_array[5]} & 0x0F) // the right 4 bits of BCD number

```

Here’s the resulting expression for the DateTime tag (I am not using milliseconds because they are not needed in my case, but they can be added using the toDate and Concat functions):

```python
setTime(
         getDate({[.]Year}, {[.]Month}-1, {[.]Day}),
                 {[.]Hour}, {[.]Minute}, {[.]Second}
 )

```

Attached is the JSON export for this UDT.

[UDT\_S7\_Date\_And\_Time.json](https://forum.inductiveautomation.com/uploads/short-url/o8jiMrSxFdHc5msjl5EW6S6HqW5.json) (3.4 KB)

[Previous page](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198.md?page=1)
