# Read Siemens S1500 Date\_And\_Time value

**URL:** <https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348>\
**Category:** Ignition\
**Created:** [December 20, 2023, 6:55am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348 "2023-12-20T06:55:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiao\_Xiao](https://avatars.discourse-cdn.com/v4/letter/x/58f4c7/32.png) [@Xiao\_Xiao](https://forum.inductiveautomation.com/u/Xiao_Xiao)\
**Post date:** [December 20, 2023, 6:55am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/1 "2023-12-20T06:55:12Z")

</div>

I try to read a "Date\_And\_Time" value in PLC  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28b304e12781bf3b28170d0f5d155ef88c369757.png)  
I used the datetime tag  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/5654002cab8678a820e79649c73931c39c00a236.png)  
The quaility is

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/9/a978b0998ccbf39f4906f0242ed8e4cfed1acccf.png)  
My colleague said they used LDT to fix the problem. But in my case, the datablock is an interface that means there will be a lot of places need to be changed if I change the type from "Date\_And\_Time" to LDT. So how can I fix this problem?

---

<div class="post-metadata">

**Author:** ![Arnaud\_Declerck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/arnaud_declerck/32/44872_2.png) [@Arnaud\_Declerck](https://forum.inductiveautomation.com/u/Arnaud_Declerck)\
**Post date:** [December 20, 2023, 6:59am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/2 "2023-12-20T06:59:46Z")

</div>

Hi @Xiao_Xiao,

Can you try to read the value in long and then use the fromMillis function to convert to a date ?

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [December 20, 2023, 7:12am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/3 "2023-12-20T07:12:54Z")

</div>

If you have version **8.1.29** of Ignition you should be able to read the Datetime directly. So the path will be something like `DBxyz,DT102`

---

<div class="post-metadata">

**Author:** ![Xiao\_Xiao](https://avatars.discourse-cdn.com/v4/letter/x/58f4c7/32.png) [@Xiao\_Xiao](https://forum.inductiveautomation.com/u/Xiao_Xiao)\
**Post date:** [December 20, 2023, 7:35am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/4 "2023-12-20T07:35:45Z")

</div>

Thank you, my ignition version is **8.1.32** and in my case the PLC is opc server and ignition is the client, so I don't use DB address to find the tag.

---

<div class="post-metadata">

**Author:** ![Xiao\_Xiao](https://avatars.discourse-cdn.com/v4/letter/x/58f4c7/32.png) [@Xiao\_Xiao](https://forum.inductiveautomation.com/u/Xiao_Xiao)\
**Post date:** [December 20, 2023, 7:40am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/5 "2023-12-20T07:40:07Z")

</div>

Hello, I have tried it. And it doesn't work

```auto
Error_TypeConversion("Cannot coerce value '[Ljava.lang.Short;@4add1b3c' into type: class java.lang.Long")

```

---

<div class="post-metadata">

**Author:** ![Arnaud\_Declerck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/arnaud_declerck/32/44872_2.png) [@Arnaud\_Declerck](https://forum.inductiveautomation.com/u/Arnaud_Declerck)\
**Post date:** [December 20, 2023, 7:48am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/6 "2023-12-20T07:48:29Z")

</div>

Hi,  
If you use OPC UA. You can browse the PLC opc server and import the tag in Ignition. Does that give you also and error ?

---

<div class="post-metadata">

**Author:** ![Xiao\_Xiao](https://avatars.discourse-cdn.com/v4/letter/x/58f4c7/32.png) [@Xiao\_Xiao](https://forum.inductiveautomation.com/u/Xiao_Xiao)\
**Post date:** [December 20, 2023, 8:04am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/7 "2023-12-20T08:04:53Z")

</div>

Of course, I have done it

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/5/35f4a98c96b492bf85aed25d20974abde5e7cd23.png)  
But it doen't work.

---

<div class="post-metadata">

**Author:** ![Arnaud\_Declerck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/arnaud_declerck/32/44872_2.png) [@Arnaud\_Declerck](https://forum.inductiveautomation.com/u/Arnaud_Declerck)\
**Post date:** [December 20, 2023, 8:41am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/8 "2023-12-20T08:41:28Z")

</div>

I was thinking like that.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/9/a96b00af7eb2e75ae0541ff2dad03a953a246f2e.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1be905352a67de65cc833bdfcbc0b159419cf4a4.png)  
Browse until you find the correct tag and use the arrow to import into ignition. This will create the tag and use the correct data type (if supported). Because with your method, maybe the dateTime data type is not the one you need to use. I don't have a siemens plc running for the moment so i cannot test it by myself.

---

<div class="post-metadata">

**Author:** ![Xiao\_Xiao](https://avatars.discourse-cdn.com/v4/letter/x/58f4c7/32.png) [@Xiao\_Xiao](https://forum.inductiveautomation.com/u/Xiao_Xiao)\
**Post date:** [December 20, 2023, 8:57am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/9 "2023-12-20T08:57:40Z")

</div>

Follow you steps, I can read the data as short array. But I have no idea how to deal with these shorts......  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/5435e46d7ad7d6265be087edbf66e680507d1b90.png)  
I try to convert these as bit array then convert to datetime, but the date show 987-03-04.....

---

<div class="post-metadata">

**Author:** ![Arnaud\_Declerck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/arnaud_declerck/32/44872_2.png) [@Arnaud\_Declerck](https://forum.inductiveautomation.com/u/Arnaud_Declerck)\
**Post date:** [December 20, 2023, 9:33am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/10 "2023-12-20T09:33:01Z")

</div>

> <https://stackoverflow.com/questions/61793154/issue-reading-dt-date-and-time-from-opc-ua-siemens-server-c>

This is for C# but you can check if it's possible to implement it in Pyhon

---

<div class="post-metadata">

**Author:** ![Arnaud\_Declerck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/arnaud_declerck/32/44872_2.png) [@Arnaud\_Declerck](https://forum.inductiveautomation.com/u/Arnaud_Declerck)\
**Post date:** [December 20, 2023, 11:41am UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/11 "2023-12-20T11:41:33Z")

</div>

hi @Xiao_Xiao ,

```auto
#Tagpath datetime Array[8]
tagPaths = '[default]var'
#read value
results=system.tag.readBlocking(tagPaths)
#Check if results
if len(results)>0:
	#Extract value for year
	val = results[0].value[0]
	year = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Check if value is 21th century
	if year <90:
		year +=2000
	else:
		year += 1900
	#Extract value for month
	val = results[0].value[1]
	month = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for day
	val = results[0].value[2]
	day = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for hour
	val = results[0].value[3]
	hour = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for minute
	val = results[0].value[4]
	min = ((val & 0xf0) / 16)*10 + (val & 0xf)
	#Extract value for seconds
	val = results[0].value[5]
	sec = ((val & 0xf0) / 16)*10 + (val & 0xf)

	#Convert to time
	from java.util import Calendar
	cal = Calendar.getInstance()
	cal.set(year, month-1, day, hour, min, sec)
	print cal.getTime()

```

This is a quick code i writed in the script console. It should be quite easy to adapt it for your use. This allow only to read from the PLC not to write back.

Regards

---

<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:** [December 20, 2023, 12:40pm UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/12 "2023-12-20T12:40:35Z")

</div>

The Siemens OPC UA server does not model Date\_And\_Time types as OPC UA DateTime values, but rather as the internal byte array value.

My generous guess as to why is that this value is essentially a date/time _string_, pre-rendered, with no fixed timezone or epoch associated with it, so they can't convert it to a UTC DateTime value without potentially converting the value to a different time than was intended.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [December 20, 2023, 1:28pm UTC](https://forum.inductiveautomation.com/t/read-siemens-s1500-date-and-time-value/83348/13 "2023-12-20T13:28:10Z")

</div>

Its been a while, on a project a few years ago, I managed to find this UDT someone made, and got it working for reading and writing to that data type. Not sure if it will fit your use case.

> [@SIEMENS Driver DATE\_AND\_TIME values](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/21):
>
> Here you go. [Pantalla\_ejemplo\_date\_and\_time\_2019-12-27\_1520.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/86d5d779f0cabd72dea62f736f79fec8808fa076.proj) (5.4 KB) [Ignition\_udt\_date\_and\_time.xml](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/2bc438550284247dc73b26a9524c55bc893f1a89.xml) (4.7 KB) It’s a DataType that has a value for reading date\_and\_time and a value for writing back to PLC. Might not be the best solution but it works (at least in my case).
