# Expression tag to convert minutes to hh:mm:ss

**URL:** <https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154>\
**Category:** Ignition\
**Created:** [October 7, 2014, 8:50pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154 "2014-10-07T20:50:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbackus](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tbackus/32/5091_2.png) [@tbackus](https://forum.inductiveautomation.com/u/tbackus)\
**Post date:** [October 7, 2014, 8:50pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/1 "2014-10-07T20:50:34Z")

</div>

Could someone help me with using and expression tag to convert something like:

91.50 minutes into 01:31:30

Is it even possible??

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 7, 2014, 9:10pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/2 "2014-10-07T21:10:35Z")

</div>

Not pretty, but it seems to work:

numberFormat(floor({_GenericSim_/Writeable/WriteableFloat1} / 60),"#0")+":"+numberFormat(60\*(({_GenericSim_/Writeable/WriteableFloat1} / 60)-floor({_GenericSim_/Writeable/WriteableFloat1} / 60)),“00”)+":" + numberFormat(60\*({_GenericSim_/Writeable/WriteableFloat1} - floor({_GenericSim_/Writeable/WriteableFloat1})),“00”)

Let me know if you want the parts broken down and explained.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 8, 2014, 10:59am UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/3 "2014-10-08T10:59:34Z")

</div>

I have a script for it:

`def convert(type, input):
  import datetime
  if type=='min':
    return str(datetime.timedelta(minutes=input))
  if type=='sec':
      return str(datetime.timedelta(seconds=input))`  
You can either import the attached file into app, or shared scripts if you have 7.7.

Your expression tag becomes

[code]runscript(app.hms.convert(‘min’, value\_to\_convert))

-OR-

runscript(shared.hms.convert(‘min’, value\_to\_convert))[/code]

It can also convert seconds:

[code]runscript(app.hms.convert(‘min’, value\_to\_convert))

-OR-

runscript(shared.hms.convert(‘min’, value\_to\_convert))[/code]  
[hms.py](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/4aedcb2a57debd3f406709471d6301267597e2d5.py) (181 Bytes)

---

<div class="post-metadata">

**Author:** ![tbackus](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tbackus/32/5091_2.png) [@tbackus](https://forum.inductiveautomation.com/u/tbackus)\
**Post date:** [October 8, 2014, 1:18pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/4 "2014-10-08T13:18:43Z")

</div>

Thanks Kathy and Jordan, I will give both of them a try.

---

<div class="post-metadata">

**Author:** ![aramirez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aramirez/32/5283_2.png) [@aramirez](https://forum.inductiveautomation.com/u/aramirez)\
**Post date:** [October 29, 2018, 7:11pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/5 "2018-10-29T19:11:49Z")

</div>

Hi,  
I tested and worked fine this one: runscript(“shared.hms.convert(‘sec’, 120)”)

BUT when I try to run using a property value like this:  
runscript(“shared.hms.convert(‘sec’, {Pozo\_ICH\_v3.TiempoOFF.intValue})”)  
I got the following error message:

Exception: Error executing expression binding on  
Pozo\_ICH\_v3.Pozo\_ICH\_v3.Label 24.text  
caused by ExpressionException: Error parsing script for runScript() expression: SyntaxError: (“mismatched input ‘}’ expecting COLON”, (‘expression:runScript’, 1, 68, “\_\_RESULT = shared.hms.convert(‘sec’, {Pozo\_ICH\_v3.TiempoOFF.intValue})\n”))

```
caused by SyntaxError: ("mismatched input '}' expecting COLON", ('<expression:runScript>', 1, 68, "__RESULT = shared.hms.convert('sec', {Pozo_ICH_v3.TiempoOFF.intValue})\n"))

```

Ignition v7.9.9 (b2018081621)  
Java: Oracle Corporation 1.8.0\_144

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 29, 2018, 7:32pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/6 "2018-10-29T19:32:29Z")

</div>

{Pozo\_ICH\_v3.TiempoOFF.intValue} ends up as a literal string. You’ll need to concatenate the value into it. Try:

```auto
runscript(concat("shared.hms.convert('sec', ", toString({Pozo_ICH_v3.TiempoOFF.intValue}), ")"))

```

---

<div class="post-metadata">

**Author:** ![aramirez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aramirez/32/5283_2.png) [@aramirez](https://forum.inductiveautomation.com/u/aramirez)\
**Post date:** [October 29, 2018, 7:33pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/7 "2018-10-29T19:33:33Z")

</div>

> [@JordanCClark](#):
>
> runscript(concat("shared.hms.convert('sec', ", toString({Pozo\_ICH\_v3.TiempoOFF.intValue}), ")"))

Thank you... works perfect!

---

<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:** [October 29, 2018, 7:35pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/8 "2018-10-29T19:35:58Z")

</div>

You can also use the newer runScript syntax to avoid the tricky/brittle concatentation:  
`runScript("shared.hms.convert", 0, "sec", {Pozo_ICH_v3.TiempoOFF.intValue})`

---

<div class="post-metadata">

**Author:** ![aramirez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aramirez/32/5283_2.png) [@aramirez](https://forum.inductiveautomation.com/u/aramirez)\
**Post date:** [October 29, 2018, 7:37pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/9 "2018-10-29T19:37:33Z")

</div>

> [@paul-griffith](#):
>
> runScript("shared.hms.convert", 0, "sec", {Pozo\_ICH\_v3.TiempoOFF.intValue})

Better idea... thanks!

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [October 30, 2018, 12:59pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/10 "2018-10-30T12:59:11Z")

</div>

IMO, it can just as easily be done without script.

- start from a date (midnight)
- add minutes or seconds like you want (needs to be integers, if you want high precision, you can add milliseconds as integers)
- format as “HH:mm:ss”

This doesn’t work if the hours value can reach more than 24 hours, but apart from that, it’s quite concise and easy to understand IMO.

```auto
dateFormat(
	addSeconds(
		getDate(1970,1,1),
		toInt({Root Container.value} * 60)
	),
	"HH:mm:ss"
)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 30, 2018, 5:27pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/11 "2018-10-30T17:27:00Z")

</div>

When I wrote it four years ago, not all of those expression functions existed. 🙂

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 30, 2018, 9:44pm UTC](https://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/12 "2018-10-30T21:44:31Z")

</div>

We just assumed you could see into the future. 😉
