# Format of Time and Adding in perspective

**URL:** <https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829>\
**Category:** Ignition\
**Tags:** python, ignition80, ignition81, scripting, perspective\
**Created:** [February 14, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829 "2023-02-14T14:43:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [February 14, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/1 "2023-02-14T14:43:08Z")

</div>

Hi connection.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5fee6628aa0b0f2aa26b00f20a7b93ce66b2d61f.png)  
I have **start Time** and **end Time** like **shift** wise so, I have used the numeric field. for the start and end time so need to calculate duration. But i am not sure to get the correct format. of time like I need only hours and minutes. I need to entry the \*\*start and end time Manual. I need format of of time in hours and minutes. After that need to display the **End Time - Start Time** in the duration last column

Thank you.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 14, 2023, 4:34pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/2 "2023-02-14T16:34:54Z")

</div>

I'm not exaclty following what you are asking, but you'll most likely need to set the start and end times to labels and add a format transform.

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

You'll also probably want to look at these system functions  
`system.date.minutesBetween()`  
`system.date.parse()`  
`system.date.format()`  
[https://docs.inductiveautomation.com/display/DOC81/System+Functions](https://docs.inductiveautomation.com/display/DOC81/System+Functions)

---

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [February 15, 2023, 12:04pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/3 "2023-02-15T12:04:43Z")

</div>

Hi @dkhayes117

I need to enter the shift timing. Manual From Scada  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e82e893bef85e95b4c2873d9fdc23e9e18b31f38.png)  
this what exactly look like in vision. same has I need to do it in perspective.

Quite difficult to understand which component need to use un perspective.

Getting doubts on **what format I need to use**. for entering manual, form the ignition in HH=hours & MM=minutes. It's shouldn't exceed more than 24hour **s Start Time or End Time. Per shift 8hrs**. but some time alternative shift will reduce or exceed their time. Duration will be calculated by the  
expression like **end time - minus start time**

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [February 15, 2023, 4:33pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/4 "2023-02-15T16:33:10Z")

</div>

This can be accomplished using dateTimeInputs for the start and end time and a label for the duration:  
You can either keep the arrows or hide them  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/e/eee4f3966c662efb5c01cb60d6e28478521c9231.png)

setup for dateTimeInputs:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0df5ab110d293bc0e6281605edc00687bbdfa79a.png)  
To hide the spinner arrows just set the style of the component to: `{ "overflow": "hidden" }`  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d25e0c88c364c4ee148c3e172c86a5be1d3a662.png)  
**Note: you need to make the dateTimeInput small enough vertically for the overflow:hidden prop to hide the arrows**

here's the expression I'm using for the duration label:

```auto
if(
	{../startDate.props.value} > {../endDate.props.value}, // date spans into next day
	stringFormat("%02d:%02d",
		hoursBetween({../startDate.props.value}, addDays({../endDate.props.value}, 1)),
		minutesBetween({../startDate.props.value}, addDays({../endDate.props.value}, 1)) % 60
	),
	stringFormat("%02d:%02d",
		hoursBetween({../startDate.props.value}, {../endDate.props.value}),
		minutesBetween({../startDate.props.value}, {../endDate.props.value}) % 60
	)
)

```

Credit goes to Paul for the duration calculation:

> [@Convert seconds to HH MM SS](https://forum.inductiveautomation.com/t/convert-seconds-to-hh-mm-ss/8739/9):
>
> This is almost the “right” answer - slightly cleaner/better is to just use [stringFormat](https://docs.inductiveautomation.com/display/DOC79/stringFormat): stringFormat("%02d:%02d:%02d", hoursBetween({Root Container.Popup Calendar.date}, now()), minutesBetween({Root Container.Popup Calendar.date}, now()) % 60, secondsBetween({Root Container.Popup Calendar.date}, now()) % 60 ) Note that it’s worth a disclaimer that this will “break” if you overflow 24 hours. You can solve that with an additional if statement and more complex logic, but I’ll leave that for…

---

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [February 16, 2023, 12:25pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/5 "2023-02-16T12:25:04Z")

</div>

**Thank you!! @Matthew.gaitan.**

---

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [February 16, 2023, 1:35pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/6 "2023-02-16T13:35:38Z")

</div>

How can I get only hour? from that start time and end time. need to use in other expression.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/c/fcf2a0bd2f77ba64b9bc6fb4e696199d789b6336.png)  
This is use in vision from start time and end time. In this expression ET= End time & ST= Start Time.

same I need in perspective using above perspective components. Help me out to create this.expression  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/df7b8e2eed4346fb9241bf1d85e71ac048eb9bcb.png)

---

<div class="post-metadata">

**Author:** ![Adarsh\_Shelar](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adarsh\_Shelar](https://forum.inductiveautomation.com/u/Adarsh_Shelar)\
**Post date:** [February 16, 2023, 1:36pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/7 "2023-02-16T13:36:26Z")

</div>

In expression I need to only hours for calculation.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [February 16, 2023, 3:45pm UTC](https://forum.inductiveautomation.com/t/format-of-time-and-adding-in-perspective/69829/8 "2023-02-16T15:45:57Z")

</div>

You should just be able to delete the minutes portion from the final expression and have the format string be `%02d:00`
