# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcaan](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@alcaan](https://forum.inductiveautomation.com/u/alcaan)\
**Post date:** [September 26, 2012, 4:53pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/1 "2012-09-26T16:53:51Z")

</div>

Hi,

I have a PLC with some DATE\_AND\_TIME values (DT) that are periodically updated. The idea is use a OPC Tag for each one. But there is a problem with the format. The ignition date and time format is different from the Siemens one. SIEMENS Format is :

BYTE Contents BCD Code Limits  
0 Year 90-99h (19\_\_)  
00-89h (20\_\_)  
1 Month 01-12 h  
2 Day 01-31h  
3 Hour 00-23h  
4 Minute 00-59h  
5 Second 00-59h  
6 MSEC(high)  
7 MSEC (low) 000-999h

The only solution I found is to put every byte in different tags and then generate a tag that is a String combining the diferent values. But this involves using 7 tags and some code for something that has to be simple. There is also the problem that doing this you need a function to transform from decimal to hex. Is there a easier and more direct solution?

---

<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:** [September 26, 2012, 4:58pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/2 "2012-09-26T16:58:49Z")

</div>

The Siemens driver doesn’t have a DT datatype, so there’s probably not a better way.

---

<div class="post-metadata">

**Author:** ![alcaan](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@alcaan](https://forum.inductiveautomation.com/u/alcaan)\
**Post date:** [September 26, 2012, 5:03pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/3 "2012-09-26T17:03:09Z")

</div>

Ok, thanks. But then there is an easy and standard way to tranform de values I recive in decimal into Hexadecimal? Because the only way I found is using some self made code.

---

<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:** [September 26, 2012, 5:15pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/4 "2012-09-26T17:15:47Z")

</div>

Hmm, it doesn’t really look like it. Kinda seems like we should add expression functions that can convert either way…

---

<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:** [September 26, 2012, 5:31pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/5 "2012-09-26T17:31:30Z")

</div>

If you have access to the plc programm there is a workaround. You can use the system functions DT\_TOD and DT\_DATE to convert a date into days and time of day. The DATE is an 16-bit value with the days since 1990-01-01 and TOD is a 32-bit value with the count of milliseconds since midnight. These value can easily be converted to a java date in Ignition.  
I added a function to our plc programs that converts all DT values and stores them in a seperate datablock which is then read by Ignition.

---

<div class="post-metadata">

**Author:** ![alcaan](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@alcaan](https://forum.inductiveautomation.com/u/alcaan)\
**Post date:** [September 26, 2012, 6:26pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/6 "2012-09-26T18:26:09Z")

</div>

Thank you Chi for your tips. But the problem is that I only have control over the ignition. For the PLC code I have to negotiate with the client, and so far he has been reluctant to change the code of them.

---

<div class="post-metadata">

**Author:** ![Michael.Stofan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.stofan/32/3342_2.png) [@Michael.Stofan](https://forum.inductiveautomation.com/u/Michael.Stofan)\
**Post date:** [September 27, 2012, 5:12pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/7 "2012-09-27T17:12:09Z")

</div>

I’ve added a feature request in our system for the expression function mentioned earlier. Cheers.

---

<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:** [September 27, 2012, 7:33pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/8 "2012-09-27T19:33:49Z")

</div>

I did some digging in my bag of discarded solutions, so here is what i tried initially (not really nice but it works)  
You need to get the plc data in two 32-bit tags (Driver format D). So when date is stored in datablock 50 at adress 0, the tags are [S7]DB50,D and [S7]DB50,D4.  
Make an expression tag (e.g. S7DateVal) with following expression:

```auto
({[.]DB50DD0}<<32) + {[.]DB50DD4}
```

All of the above tags need to have INT8 as datatype.

Create an additional memory tag of type DATETIME with the same name added ‘DT’ at the end (S7DateValDT).

Put the following code in a tag change script:

```auto
val = newValue.value
val = val >> 4	# Ignore DayOfWeek
msec = ((val & 0xf00) / 256)*100
msec += ((val & 0xf0) / 16)*10
msec += (val & 0xf)
val = val >> 12
sec = ((val & 0xf0) / 16)*10 + (val & 0xf)
val = val >> 8
min = ((val & 0xf0) / 16)*10 + (val & 0xf)
val = val >> 8
hour = ((val & 0xf0) / 16)*10 + (val & 0xf)
val = val >> 8
day = ((val & 0xf0) / 16)*10 + (val & 0xf)
val = val >> 8
month = ((val & 0xf0) / 16)*10 + (val & 0xf) - 1	# Java month starts with 0
val = val >> 8
year = ((val & 0xf0) / 16)*10 + (val & 0xf)
if year<90:
	year += 2000
else:
	year += 1900
#print "%d %d %d %d %d %d %d" % (msec, sec, min, hour, day, month, year)
from java.util import Calendar
cal = Calendar.getInstance()
cal.set(year, month, day, hour, min, sec)
cal.set(Calendar.MILLISECOND, msec)
#print cal.getTime()
system.tag.write(event.tagPath.toStringFull()+'DT', cal.getTime()) 
```

Add the expression tag to the tag change script.  
Now, on every change of your plc data the …DT tag will be updated.

Be aware the access to two seperate values might not be consistent, so don’t try this with fast changing values.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![alcaan](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@alcaan](https://forum.inductiveautomation.com/u/alcaan)\
**Post date:** [September 27, 2012, 8:36pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/9 "2012-09-27T20:36:04Z")

</div>

Thank you very much Chi! I will try this solution and let you know if is consistent in my system.

---

<div class="post-metadata">

**Author:** ![siggi](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@siggi](https://forum.inductiveautomation.com/u/siggi)\
**Post date:** [March 19, 2013, 12:43pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/10 "2013-03-19T12:43:03Z")

</div>

Since the last post in this thread, have there been any new features w.r.t. conversion between Siemens TOD and DATE formats and the standard (Ignition) DATETIME format?

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [April 11, 2013, 3:35pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/11 "2013-04-11T15:35:40Z")

</div>

This feature has not been added to the driver yet. It is still on the list of feature requests to add.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [January 12, 2014, 3:23pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/12 "2014-01-12T15:23:33Z")

</div>

Any progress on this?

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [January 24, 2014, 10:30pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/13 "2014-01-24T22:30:41Z")

</div>

I did some further checking on this and it looks like the following expression functions are in the works:  
toHex() - takes a decimal number and returns a string representing the hex value  
fromHex() - takes a hex string and returns the decimal number equivalent

No hard timeline on this but it is being worked on currently.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [January 27, 2014, 4:12pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/14 "2014-01-27T16:12:10Z")

</div>

It doesn’t address the original post, but at least you have this. (tested in Ignition 7.5.11, Java 7 u45)

```auto
def fromHex(x):
	return int(x, 16)

def toHex(x):
	return "%X" % x
```

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 19, 2018, 2:46pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/15 "2018-04-19T14:46:14Z")

</div>

We REALLY NEED this DateTime format in Siemens driver! 👋

---

<div class="post-metadata">

**Author:** ![francois.morin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/francois.morin/32/15064_2.png) [@francois.morin](https://forum.inductiveautomation.com/u/francois.morin)\
**Post date:** [August 8, 2018, 5:24pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/16 "2018-08-08T17:24:24Z")

</div>

Any news on DATE\_AND\_TIME being supported in Siemens driver ?

---

<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:** [August 8, 2018, 5:31pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/17 "2018-08-08T17:31:09Z")

</div>

Sorry guys, there hasn’t been any movement on this. I’m not sure when it will happen.

---

<div class="post-metadata">

**Author:** ![fnazzali](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@fnazzali](https://forum.inductiveautomation.com/u/fnazzali)\
**Post date:** [May 15, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/19 "2019-05-15T19:21:58Z")

</div>

Thank you Chi!

The script provided works perfectly for Ignition 7.9.10 but not on Ignition 8 when using a Gateway Event script. After talking with support, we were able to get it functioning by using a Tag Event Script on the expression tag “S7DateVal”. Please see below for the script used in Ignition 8.

```auto
	val = currentValue.value
	val = val >> 4	# Ignore DayOfWeek
	msec = ((val & 0xf00) / 256)*100
	msec += ((val & 0xf0) / 16)*10
	msec += (val & 0xf)
	val = val >> 12
	sec = ((val & 0xf0) / 16)*10 + (val & 0xf)
	val = val >> 8
	min = ((val & 0xf0) / 16)*10 + (val & 0xf)
	val = val >> 8
	hour = ((val & 0xf0) / 16)*10 + (val & 0xf)
	val = val >> 8
	day = ((val & 0xf0) / 16)*10 + (val & 0xf)
	val = val >> 8
	month = ((val & 0xf0) / 16)*10 + (val & 0xf) - 1	# Java month starts with 0
	val = val >> 8
	year = ((val & 0xf0) / 16)*10 + (val & 0xf)
	if year<90:
		year += 2000
	else:
		year += 1900
	#print "%d %d %d %d %d %d %d" % (msec, sec, min, hour, day, month, year)
	from java.util import Calendar
	cal = Calendar.getInstance()
	cal.set(year, month, day, hour, min, sec)
	cal.set(Calendar.MILLISECOND, msec)
	#print cal.getTime()
	system.tag.write(" **S7DateValDT PATH HERE**", cal.getTime()) 

```

---

<div class="post-metadata">

**Author:** ![ccaceres](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@ccaceres](https://forum.inductiveautomation.com/u/ccaceres)\
**Post date:** [December 13, 2019, 6:26pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/20 "2019-12-13T18:26:38Z")

</div>

Any sugestion for created Date\_And\_Time and UDint in ignition?

---

<div class="post-metadata">

**Author:** ![maidamar](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@maidamar](https://forum.inductiveautomation.com/u/maidamar)\
**Post date:** [December 27, 2019, 6:31pm UTC](https://forum.inductiveautomation.com/t/siemens-driver-date-and-time-values/5198/21 "2019-12-27T18:31:32Z")

</div>

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).

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