# OPC Tag Value Seconds to HH:MM:SS via Expression Tag

**URL:** <https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [April 13, 2021, 5:18pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544 "2021-04-13T17:18:37Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [April 28, 2021, 4:25pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544/21 "2021-04-28T16:25:28Z")

</div>

Are you sure that is exactly the expression you are using? When I put 143,164 into my expression posted above, it returns `01:15:46:04` correctly.

```auto
if(
	isNull(143164),
	"00:00:00:00",
	stringFormat(
		"%02d:%02d:%02d:%02d",
		toInt(floor(143164 / (24 * 3600))),
		toInt(floor(143164 % (24 * 3600) / 3600)),
		toInt(floor(143164 % 3600 / 60)),
		toInt(floor(143164 % 60))
	)
)

```

---

<div class="post-metadata">

**Author:** ![jnqplas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jnqplas/32/4054_2.png) [@jnqplas](https://forum.inductiveautomation.com/u/jnqplas)\
**Post date:** [April 28, 2021, 4:28pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544/22 "2021-04-28T16:28:24Z")

</div>

WAIT! You’re right. Apparently I was closing the floor() before the mathematical operations. I see this now that I copied your expression below mine. I knew I had to be missing something simple.

I swear I tried that, but I must have had something else going on. Thank you for your help!

---

<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:** [April 28, 2021, 5:26pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544/23 "2021-04-28T17:26:59Z")

</div>

Not an expression, but another option would be to do this in a script library:

```auto
from java.util import Locale
from com.inductiveautomation.ignition.common import FormatUtil

def formatTime(time):
	return FormatUtil.formatDuration(Locale.getDefault(), time, FormatUtil.DurationFormatStyle.COMPACT, False)

```

```auto
>>> formatTime(1123311123)
u'13d 00:01:51'
>>> formatTime(1123311)
u'00:18:43'
>>> formatTime(38460)
u'00:00:38'
>>> formatTime(38460123)
u'10:41:00'

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 10, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544/24 "2023-08-10T14:45:52Z")

</div>

This worked, gave me `00:00:00`.  
Thanks @Kevin.Herron

```auto
	stringFormat(
		"%02d:%02d:%02d",
		toInt(floor({[~]Tag}/3600)),
		toInt(floor({[~]Tag}%3600/60)),
		toInt(floor({[~]Tag}%60)))

```

Edited

---

<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 10, 2023, 2:49pm UTC](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544/25 "2023-08-10T14:49:04Z")

</div>

You’re missing the closing parenthesis for the `stringFormat` function.

[Previous page](https://forum.inductiveautomation.com/t/opc-tag-value-seconds-to-hhss-via-expression-tag/45544.md?page=1)
