# Tag Up-Time Counter

**URL:** <https://forum.inductiveautomation.com/t/tag-up-time-counter/26987>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [July 30, 2019, 1:49pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987 "2019-07-30T13:49:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwkidd](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@cwkidd](https://forum.inductiveautomation.com/u/cwkidd)\
**Post date:** [July 30, 2019, 1:49pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987/1 "2019-07-30T13:49:42Z")

</div>

Hi there! Right now I’m attempting to create a status page for all of our RM systems that we have active (about 14). In addition to having the simple Up/Down indication- which i have- I was asked to have a counter next to each system indicating how much time that system had spent up or down. I’ve run through several different ways to attempt this, but I’m a bit stuck.

All I would need is a simple counter for hours, minutes, seconds…but I’m a bit of a novice when it comes to scripting.

Help!

---

<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:** [July 30, 2019, 2:34pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987/2 "2019-07-30T14:34:10Z")

</div>

If you want to know how long since the last change you can do that through an expression tag using:

```auto
dateDiff({[.]tag.LastChange},now(),"seconds")

```

That would find the time since the tag changed last. If your pointed at a running bit it would give you a count for how long its been running or how long it has been down. You can also put it in an if statement if you want to limit it to only when it is running or stopped.

To turn it into a time format you can do something like.

```auto
try(toStr(dateFormat( 
	setTime(dateDiff({[.]tag.LastChange},now(),"seconds"),
		round(floor({[.]DownTime}/3600)),
		round(floor(({[.]DownTime}/60)%60)),
		round(({[.]DownTime}%60))),
			"HH:mm:ss"),0),'00:00:00')

```

I put it in a try so it would return 00:00:00 if your time is 0 seconds.

---

<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:** [July 30, 2019, 2:58pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987/3 "2019-07-30T14:58:45Z")

</div>

IMO, I would use a transaction group set to whatever time resolution you want. Usually, 30 seconds is more than good enough. You can then use this data to tally up/down time as well as have have context on when up and down time happens. Easily chartable for management types.

I also have our transaction groups set to purge at 14 days, since no-one at my facility ever seems to look back any further.

---

<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:** [July 30, 2019, 4:04pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987/4 "2019-07-30T16:04:39Z")

</div>

I assumed he wanted simple indication. If he wants a running tally the transaction group would work better for logging the data. I’m using a similar tag to what I mentioned just for a downtime counter on some equipment tied to an alarm if it reaches a set value. For downtime reporting I do the same using transaction groups.

---

<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:** [July 30, 2019, 6:05pm UTC](https://forum.inductiveautomation.com/t/tag-up-time-counter/26987/5 "2019-07-30T18:05:03Z")

</div>

Perhaps so, but the next logical step is historical data, even if they don’t know they want it. May as well design for it from the start. 😁
