# Creating a simple countdown timer

**URL:** <https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 14, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038 "2023-06-14T19:06:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [June 14, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/1 "2023-06-14T19:06:06Z")

</div>

Hi all. I'm currently trying to build a simple LED display count-down timer in perspective, that's formatted as HH:mm:ss. All I want it to do is reset to a specified time via a button and then proceed to infinitely countdown at an increment of 1 second till it reaches 0. It would be helpful if this could be done using the tag system so I can record the elapsed timestamp for a report later.

Thank you,

Cam

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2023, 8:09pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/2 "2023-06-14T20:09:06Z")

</div>

- Create a memory tag `futureTime` of type timestamp (or whatever it's called).
- Add an event to the button, have it calculate the future time using [system.date.add\*](https://docs.inductiveautomation.com/pages/viewpage.action?pageId=24449810) and write that to the tag.
- Add a label (or your 1970s LED display if you insist) and create an expression binding which subtracts `now(1000)` from the `futureTime` tag. Use the expression `dateFormat` function to give you `HH:mm:ss`.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [June 14, 2023, 8:11pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/3 "2023-06-14T20:11:02Z")

</div>

Try something like this, should get you most of the way there:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/651686a61bc13661b922e01d7592cb5a5ff2e70f.png)  
I used a date time input and then an expression binding on the LED component with a script transform (code i found from one of @JordanCClark's posts).

---

<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:** [June 14, 2023, 8:59pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/4 "2023-06-14T20:59:53Z")

</div>

A pure expression. Should save an extra round trip to the gateway to run a script:

```auto
if(secondsBetween(now(), {path/to/time/value}) < 0,
	'0:00:00',
	toInt(floor(secondsBetween(now(), {path/to/time/value})/3600)) 
	  + ':'
	  + numberFormat(toInt(floor(secondsBetween(now(), {path/to/time/value})/60)) % 60, '00') 
	  + ':'
	  + numberFormat(secondsBetween(now(), {path/to/time/value}) % 60, '00')
  )

```

---

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [June 14, 2023, 9:15pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/5 "2023-06-14T21:15:02Z")

</div>

This looks like exactly what I would want but I have no idea where to put it. Would you be able to give me some instructions as to how to get this running and bind it to my display?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [June 14, 2023, 9:25pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/6 "2023-06-14T21:25:29Z")

</div>

Add an expression binding on your led component's value property:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/6/c6a0142d7c219c940aab2ab32c30c569fb0d5034.png)

Use Jordan's code, but update it to wherever you are storing the time.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/dbe2f092f3df5b06aa059575abbb1c0ddb2f2449.png)

My example does not have a button, if you want that you have a number of ways to set the time value when you click the button.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2023, 9:48pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/7 "2023-06-14T21:48:03Z")

</div>

![Countdown timer](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/3/033119ede3c163030354848fbb88d2df85210c3c.gif)

_Right-click | Open image in new tab_ for larger view.

---

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [June 14, 2023, 10:00pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/8 "2023-06-14T22:00:16Z")

</div>

Ohhh! Thank you very much! I'm sorry, I'm still very new at this stuff but I appreciate your efforts.

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 26, 2024, 4:51pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/9 "2024-03-26T16:51:56Z")

</div>

when I tried this script it says left operand is null

---

<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 26, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/10 "2024-03-26T17:48:39Z")

</div>

Refer to @Transistor's post above. I'm guessing you tried to use the expression directly.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 26, 2024, 5:57pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/11 "2024-03-26T17:57:05Z")

</div>

> [@Marcus\_Stanley](#):
>
> ... when I tried this script ...

That's not a **script**. It's an **expression** and it goes into an **expression binding** as shown in my animation.

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 26, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/12 "2024-03-26T18:02:44Z")

</div>

got it thanks

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 26, 2024, 6:04pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/13 "2024-03-26T18:04:29Z")

</div>

yes  
it gives me 0:00:00 but now how do I get it to countdown or bind it to a tag in the plc that is the cycle\_time

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 26, 2024, 6:09pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/14 "2024-03-26T18:09:37Z")

</div>

Marcus, you really need to show how you've set it up if you want us to debug what's wrong with the way you set it up.

> [@JordanCClark](#):
>
> `if(secondsBetween(now(), {path/to/time/value}) < 0,`

Jordan showed where to put the tagpath.

---

<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 26, 2024, 6:10pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/15 "2024-03-26T18:10:12Z")

</div>

{path/to/time/value} in the expression represents a future time.

Looking over some of your other posts are you wanting to count up for cycle time or down?

---

<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 26, 2024, 7:21pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/16 "2024-03-26T19:21:27Z")

</div>

A UDT you can use. Point the 'Running' boolian to a machine that is in cycle. Use 'Ideal Cycle Time sec' to define the countdown value.  
[udt\_CycleTime.json](https://forum.inductiveautomation.com/uploads/short-url/rx1JuFFPD10Q1oVSdVG9fRe4U0Z.json) (1.5 KB)

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 27, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/17 "2024-03-27T18:54:55Z")

</div>

![03_27_24_cycleTmr](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/5/c59287d75ad396c09f99ac43fb36dc2d55abb4b0.png)

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 27, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/18 "2024-03-27T18:59:32Z")

</div>

i never got bottom of timer to change everyday and actually keep track of real time. Also, I was trying to connect timer to plc to get realtime cycle time and count backwards from 59 sec and if timer was not reset after 59 sec then it would turn red and keep counting until reset. plus this stores 10 cycle times in history. Never got it working correctly

---

<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 27, 2024, 7:45pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/19 "2024-03-27T19:45:12Z")

</div>

> [@Marcus\_Stanley](#):
>
> Also, I was trying to connect timer to plc to get realtime cycle time

Are you using a timer in the PLC itself? If so, what PLC? Asking because, of course, different platforms have different ways of handling timers.

---

<div class="post-metadata">

**Author:** ![Marcus\_Stanley](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Marcus\_Stanley](https://forum.inductiveautomation.com/u/Marcus_Stanley)\
**Post date:** [March 27, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038/20 "2024-03-27T19:49:13Z")

</div>

controllogix Allen Bradley. but it doesn't have to be. I just thought this would be easier way of recording cycle times plus displaying on the screen how long it took to produce part

[Next page](https://forum.inductiveautomation.com/t/creating-a-simple-countdown-timer/75038.md?page=2)
