# Derived Date Tag

**URL:** <https://forum.inductiveautomation.com/t/derived-date-tag/27611>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [August 20, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611 "2019-08-20T20:56:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [August 20, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/1 "2019-08-20T20:56:23Z")

</div>

Having multiple issues with Datetime derived tag.

I’m reading and writing string-encoded UTC datetimes over OPC, and would like to use derived tags to both convert the strings to actual datetime types, while also offsetting them into the local timezone.  
The read portion of this works fine, but when writing to the derived tag I get cryptic evaluation errors.

I have the following tags:

- datetime\_r - OPC - string
- datetime\_w - OPC - string
- datetime\_utc - Derived - DateTime - source is datetime\_w
- datetime - Derived - DateTime - source is datetime\_utc

the write expression on my `datetime` tag:

```auto
addHours(
  toDate({value}),
  (-1)*getTimezoneOffset()
)

```

The evaluation error reports: `Invalid argument type for function null(date, int)`

Is `{value}` not a string, and the result of `toDate()` not a datetime?

---

<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 20, 2019, 9:19pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/2 "2019-08-20T21:19:23Z")

</div>

What’s the datatype of your `datetime` tag? String or DateTime?

What version of Ignition is this?

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [August 20, 2019, 10:23pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/3 "2019-08-20T22:23:45Z")

</div>

DateTime, updated my post for clarity.  
Ignition version 7.9.10.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [August 21, 2019, 1:41pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/4 "2019-08-21T13:41:22Z")

</div>

I don’t know if you figured this out. It doesn’t like the multiplication in the addHours part of the expression but if you wrap it in toInt() it will work. getTimezoneOffset returns a double while add hours is looking for an integer. When you do the multiplication it returns a double. Since addHours requires an int you got the error you showed.

The result is:

```auto
addHours(
  toDate({value}),
  toInt((-1)*getTimezoneOffset())
)

```

---

<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 21, 2019, 1:50pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/5 "2019-08-21T13:50:50Z")

</div>

Thanks, I hadn’t looked into this yet.

I’m leaning towards calling this a bug.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [August 21, 2019, 1:55pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/6 "2019-08-21T13:55:04Z")

</div>

To me I think it is a bug. I wouldn’t think being a regular int vs a double should stop it from working but that was the only thing I could see that it could be. Forcing it to an int got past the error though.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [August 21, 2019, 2:06pm UTC](https://forum.inductiveautomation.com/t/derived-date-tag/27611/7 "2019-08-21T14:06:48Z")

</div>

Out of curiosity I just tried one more thing. I used:

```auto
addHours(
	  toDate("2007-04-12 16:28:22"),
	  ((-1)*5)
	)

```

This also gets the expression error but if I add in the toInt it works fine. This takes away from my double vs int thought since I would assume -1 and 5 would both be looked at as int’s.
