# \[IGN-8635\]Convert UTC timestamp to readable date

**URL:** <https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 26, 2024, 5:12pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910 "2024-03-26T17:12:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 5:12pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/1 "2024-03-26T17:12:56Z")

</div>

having a bad brain day (having a cold sucks). can someone help me convert a UTC string to a readable date. i am wanting to drop this on my UDT tag so the conversion is done right at the UDT. here's the what i attempted so far:

```auto
toDate(tag('[MQTT]Edge Nodes/'+{GroupID}+'/'+{AssetName}+'/tags/gpsLastUpdated'))

```

incoming string: `032615572024`  
desired format: `Tuesday, July 19, 3003 7:07:04 PM GMT-06:00 DST`

---

<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 26, 2024, 5:16pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/2 "2024-03-26T17:16:09Z")

</div>

You've gotta give us an example of what format the string is in and what format you want...

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/3 "2024-03-26T17:19:09Z")

</div>

i was actually adding that when your message came in. i am brain dead today, but not like TOTALLY... 😆 just slow as a dead badger...

---

<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 26, 2024, 5:22pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/4 "2024-03-26T17:22:07Z")

</div>

> [@ian.sebryk](#):
>
> 032615572024

What date is this supposed to be? I'd expect ISO 8601 since you said "UTC String", but it's not.

Best guess: March 26, 2024 15:57?

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 5:27pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/5 "2024-03-26T17:27:04Z")

</div>

hm. that's a problem... i admit, i didn't examine that as the docs said the device reported a UTC string... dammit. regardless, is the expression good? i can find out what the hell this incoming number is; i have control over ensuring that comes in as an _actual_ UTC string (don't trust docs). given that incoming is correct, will the expression yield what i want?

EDIT: i should just go home, drink Buckley's, and die until tomorrow....

---

<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 26, 2024, 5:28pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/6 "2024-03-26T17:28:56Z")

</div>

I've been working through cold since Sunday too 😆

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 26, 2024, 5:31pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/7 "2024-03-26T17:31:47Z")

</div>

> [@ian.sebryk](#):
>
> will the expression yield what i want?

It doesn't seem to match any of the [supported formats](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/type-casting/toDate#description) so I'm guessing it will yield an error unless you massage the string into a more standard format.

EDIT: Actually since it's a valid integer it'll try to treat it like a UTC timestamp and parse it that way so you'd get a bogus 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:** [March 26, 2024, 5:33pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/8 "2024-03-26T17:33:24Z")

</div>

I think the leading zero rules that out.

It looks to me that it's a format like this: `"MMddHHmmyyyy"`

---

<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 26, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/9 "2024-03-26T17:35:28Z")

</div>

```auto
jshell> var df = new SimpleDateFormat("MMddHHmmyyyy")
df ==> java.text.SimpleDateFormat@48f26b00

jshell> df.setTimeZone(TimeZone.getTimeZone("UTC"))

jshell> df.parse("032615572024")
$12 ==> Tue Mar 26 08:57:00 PDT 2024

```

08:57 PDT is 15:57 UTC

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 26, 2024, 5:36pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/10 "2024-03-26T17:36:53Z")

</div>

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

Looks like the expression does ignore the leading zero and parse the string as a (edit: bogus) int timestamp.

---

<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 26, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/11 "2024-03-26T17:37:16Z")

</div>

Sure, but I assume that's just the completely wrong date/time.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 26, 2024, 5:38pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/12 "2024-03-26T17:38:24Z")

</div>

Yeah, I was just going into detail on why the expression wouldn't work on that format as written. Just edited my earlier post to hopefully remove any ambiguity

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 5:45pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/13 "2024-03-26T17:45:19Z")

</div>

so, yeah. the timestamp IS an actual UTC string... 979 years in the future. that's a little _too_ much forward thinking... 😃

the expression needs to be on the UDT. i know it works in a binding, but i want the UDT to return a readable date to the individual assets that source the UDT, thus the use of `tag()`.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 26, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/14 "2024-03-26T17:49:21Z")

</div>

Oh, so it's a Unix timestamp _in seconds_, what a weird coincidence:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39cade39fd7c998b2bb5b9c0c1f20df87a033f1b.png)

`toDate()` takes a Unix timestamp in _milli_seconds so you just need to multiply your tag value by 1000 first.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/15 "2024-03-26T17:52:06Z")

</div>

aha. 🤦‍♂️ so the expression needs to look like this then:

```auto
toDate(str(int(tag('[MQTT]Edge Nodes/'+{GroupID}+'/'+{AssetName}+'/tags/gpsLastUpdated')*1000)))

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 26, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/16 "2024-03-26T18:02:24Z")

</div>

I think Kevin is right. I'd use this expression:

```auto
runScript(
	'system.date.parse',
	0,
	concat(
		tag('[MQTT]Edge Nodes/'+{GroupID}+'/'+{AssetName}+'/tags/gpsLastUpdated'),
		'+00'
	),
	'MMddHHmmyyyyX'
)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 26, 2024, 6:13pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/17 "2024-03-26T18:13:22Z")

</div>

I attached this thread to the existing ticket for "add a dateParse analogue to expressions", since the `runScript` stuff is awkward and annoying.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 7:19pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/18 "2024-03-26T19:19:49Z")

</div>

i did something wrong:

 ![Screenshot 2024-03-26 131605](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/319eb8c3b1155fcdc379406e6aa18876c3c17d70.png)

EDIT source device is sending wrong data. undocumented flag that generates the correct UTC string, btw. so that's where the jacked up string comes from...

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [March 26, 2024, 8:53pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/19 "2024-03-26T20:53:13Z")

</div>

i'm getting the correct UTC string now (`1711485613.000000`) so i figured i could just use this expression:

```auto
toDate(tag('[MQTT]Edge Nodes/'+{GroupID}+'/'+{AssetName}+'/tags/gpsLastUpdated'))

```

buuut. it doesn't work. ☹ the `tag()` takes a string, yields a string. and `toDate()` takes a string, so this should be just fine... but it isn't. it spits out this error:

> Error\_ExpressionEval

not sure why the fails. when i try to put it on a binding, i get a different error:

> Bad\_NotFound

so now i'm confused. 😕 i just want a dang date on the UDT.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 26, 2024, 8:58pm UTC](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910/20 "2024-03-26T20:58:04Z")

</div>

'toDate()` seems to not like the float as a string, although it takes float literals with no complaints.

You can explicily parse it as a float first:

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

Not sure if the fractional portion is meaningful or not so just left it as a float. Might want to look into other conversions if you'd prefer..

[Next page](https://forum.inductiveautomation.com/t/ign-8635-convert-utc-timestamp-to-readable-date/87910.md?page=2)
