# How to Show Time (Duration, not DateTime)

**URL:** <https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514>\
**Category:** Ignition\
**Created:** [February 22, 2020, 2:52am UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514 "2020-02-22T02:52:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmart](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dmart/32/13427_2.png) [@Dmart](https://forum.inductiveautomation.com/u/Dmart)\
**Post date:** [February 22, 2020, 2:52am UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/1 "2020-02-22T02:52:13Z")

</div>

Building a project in Edge 7.9.13.  
I have a table that I am using a script to fill in the Dataset from tags, The tags are from an array of UDTs in the PLC. Everything is working except one column.  
In the PLC I am using 64 bit integers for the timestamps (UTC time in milliseconds.).  
I have a start time, a stop time, and a duration time (stop-start in PLC). This is also a 64 bit integer.  
When I display these in my table, the start and stop work fine, but the duration is off.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0140c7995b6b19002bcb23ca4877a65c1e2c84a7.png)  
It looks to be off by the timezone offset. It there a way I can read this as just time and not datetime?

The tags in the PLC look like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c453468d06b38dc012c7ad56bc4337c08c0339d2.png)

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [February 22, 2020, 3:08am UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/2 "2020-02-22T03:08:54Z")

</div>

If Ignition knows the Start and Stop time why not let it calculate the duration instead of converting the value in the plc?

---

<div class="post-metadata">

**Author:** ![Dmart](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dmart/32/13427_2.png) [@Dmart](https://forum.inductiveautomation.com/u/Dmart)\
**Post date:** [February 22, 2020, 6:15am UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/3 "2020-02-22T06:15:56Z")

</div>

The value is also needed else where in the PLC. But I’m not against calculating it in ignition also if it gives me the right format. hh:mm:ss

---

<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:** [February 22, 2020, 10:51am UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/4 "2020-02-22T10:51:45Z")

</div>

If you have the duration as miliseconds, just add it to a fixed date, and format it as a date.

`system.date.addMillis(system.date.getDate(2000, 01, 01), {duration})`

If you use the `fromMillis` function, you’ll likely get into trouble with the time zone differences, as that’s always interpreted as UTC. While `getDate` will give you the midnight of a date in the current timezone.

EDIT: sorry, didn’t notice this was scripting instead of expressions. Same principle should hold in python though, start from midnight in the current timezone, and add milliseconds to it.

---

<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:** [February 22, 2020, 12:23pm UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/5 "2020-02-22T12:23:19Z")

</div>

From a script written long ago, on a PC far, far away…

```python
# convert an integer value to a duration in h:m:s
def hms(typeIn, value):
  import datetime
  if typeIn=='min':
    return str(datetime.timedelta(minutes=value))
  if typeIn=='sec':
      return str(datetime.timedelta(seconds=value))
  if typeIn=='millis':
  	return str(datetime.timedelta(milliseconds=value))
  	
valueIn = 110002

print hms('millis', valueIn)

```

 ![2020-02-22_7-22-03](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6e55be7ae2851a184a92ca7992339b92987c3515.png)

---

<div class="post-metadata">

**Author:** ![Dmart](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dmart/32/13427_2.png) [@Dmart](https://forum.inductiveautomation.com/u/Dmart)\
**Post date:** [February 22, 2020, 3:49pm UTC](https://forum.inductiveautomation.com/t/how-to-show-time-duration-not-datetime/32514/6 "2020-02-22T15:49:48Z")

</div>

Thank for Force for that one. That gives me what I’m looking for.  
Thanks
