# Perspective Timer

**URL:** <https://forum.inductiveautomation.com/t/perspective-timer/71176>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [March 16, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176 "2023-03-16T18:12:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Guyer](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Alex\_Guyer](https://forum.inductiveautomation.com/u/Alex_Guyer)\
**Post date:** [March 16, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/1 "2023-03-16T18:12:20Z")

</div>

Hello all,  
I'm needing to display a timer within a perspective session. I have a session property "MissionTime". When a button is pressed, I want it to start incrementing a timer to that property, then I can use the session property to bind displays and labels to.  
I have tried a few things, one being-

self.session.custom.MissionTime = now()

Then do some math on that display to show a timer that started when the button is pressed. A different button press would stop the timer, and set "MissionTime" back to 0.

So far haven't been able to make this work at all, and some searching is yielding no good solutions for timers in perspective. Anyone have suggestions on how I could make this happen? Because of how dynamic my displays/sessions are, I need to make it happen without using tags.  
Thanks all!

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [March 16, 2023, 6:37pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/2 "2023-03-16T18:37:05Z")

</div>

Make two session properties: `MissionTimeStart` and `MissionTimeElapsed`.

Write the timestamp of start button press to `MissionTimeStart`. Have a binding on `MissionTimeElapsed` that calculates difference between value returned by `now()` and the timestamp stored in `MissionTimeStart`.

On stop button press, write a null to `MissionTimeStart`. Have your binding on `MissionTimeElapsed` write a 0 if it sees a null in `MissionTimeStart`, or make it default to a value of 0 if the expression fails(which it will since it can't do datetime math on a null).

example expression for `MissionTimeElapsed`:

```auto
try(dateDiff(this.custom.MissionTimeStart, now(), 'second'), 0)

```

---

<div class="post-metadata">

**Author:** ![Alex\_Guyer](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Alex\_Guyer](https://forum.inductiveautomation.com/u/Alex_Guyer)\
**Post date:** [March 16, 2023, 6:40pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/3 "2023-03-16T18:40:08Z")

</div>

I like that idea a lot. I haven't been able to successfully write now() to a session property for some reason.  
Any idea why self.session.custom.MissionTime = now() isnt working for that?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [March 16, 2023, 6:44pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/4 "2023-03-16T18:44:49Z")

</div>

When you say you can't write now() to a session property, are you trying to write it via a binding or a python script?

for the `onActionPerformed` script on the button,

```auto
self.session.custom.MissionTimeStart = system.date.now()

```

should work.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 16, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/5 "2023-03-16T18:46:43Z")

</div>

> [@Alex\_Guyer](#):
>
> `self.session.custom.MissionTime = now()`

Looks like you are mixing expression functions and jython syntax. An expression binding would be just `now(0)`. In a script, you'd do this, presumably inside an `if` block:

```auto
self.session.custom.MissionTime = system.datetime.now()

```

Heh: @ryan.white beat me by two minutes.

---

<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:** [March 16, 2023, 6:58pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/6 "2023-03-16T18:58:53Z")

</div>

Everyone beat me, but here's a view to play with. All expressions, no scripts.  
[timer\_2023-03-16\_1457.zip](https://forum.inductiveautomation.com/uploads/short-url/v8y67gF70NbRPaOQ7ONOJ1YKQsE.zip) (5.3 KB)

---

<div class="post-metadata">

**Author:** ![Alex\_Guyer](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Alex\_Guyer](https://forum.inductiveautomation.com/u/Alex_Guyer)\
**Post date:** [March 16, 2023, 7:56pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/7 "2023-03-16T19:56:41Z")

</div>

and @ryan.white Thank you. I was missing part of that. I gave it a try using

```auto
try(dateDiff(this.custom.MissionTimeStart, now(), 'second'), 0)

```

as a transform script and it was not coming out correctly.

---

<div class="post-metadata">

**Author:** ![Alex\_Guyer](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Alex\_Guyer](https://forum.inductiveautomation.com/u/Alex_Guyer)\
**Post date:** [March 16, 2023, 7:57pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/8 "2023-03-16T19:57:37Z")

</div>

This is a fanatic example. Thank you very much! Almost exactly what I am looking for, and I will be able to easily adapt it.

---

<div class="post-metadata">

**Author:** ![a.alghannam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/a.alghannam/32/75158_2.png) [@a.alghannam](https://forum.inductiveautomation.com/u/a.alghannam)\
**Post date:** [November 7, 2025, 8:11pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/9 "2025-11-07T20:11:07Z")

</div>

amazing! just add change script and do whatever you want.😁

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [December 23, 2025, 4:37pm UTC](https://forum.inductiveautomation.com/t/perspective-timer/71176/10 "2025-12-23T16:37:12Z")

</div>

this was helpful, thanks!
