[SOLVED] Set up a countdown timer based on time allotted to a task

What is the best way to display the time remaining in seconds from now() until now()+X?

Create either a memory tag or a client tag for the now()+X value and then just do a date difference for the display?

1 Like

Let’s see… now() keeps changing, so, uh, just display X ?

/me ducks and runs away :stuck_out_tongue:


No solution I found for my particular use case was easy to implement. There is no component called countdown timer after all. There should be but it made me think I’m making a mountain out of a molehill. So instead i’ll have the user click a “begin” button to indicate they are ready to start the process.

I think MMaynardUSG has the right idea. Depending on how your task starts, I’d either put a script in the button that starts the task or do a tag change script in a tag that monitors the status of the task. The script would would calculate the now()+x value and write it to a memory tag, then you can do an expression tag to get the difference for your countdown. The script should be a very simple one to write.

I do the same thing but mine counts up not down. Each job has an allotted time to complete it. The jobs are scanned as they do them at which point the job information and allotted time (SALH - Standard Allowable Labor Hours) populates the screen. The SALH gets converted to decimal minutes and displayed (times 60). At the same time, a “stop watch” starts timing. If the stop watch is below the SALH time it is displayed in green, if it goes over the SALH it turns red. A “startTime” tag is written to on scan using system.date.now() then the timer is simply an expression tag.

secondsBetween({Root Container.yourTime.startTime}, now())/60)

I have a more complicated expression than this that allows for the timer to be paused and to only display when a job is active etc, but you may not need that.

After some more thought here is what I came up with:

 abs(dateDiff(dateArithmetic({[.]time_PressButton}, {[.]setup_TimeAllotted}, "minutes"), now(), "minute"))

time_PressButton is a datetime tag.
setup_TimeAllotted is an integer tag.

This equation calculates the time the button was pressed plus some integer amount of time (in minutes). Then it takes the difference between that calculated time and now() in minutes. This is a negative value equal to setup_TimeAllotted untiil we run out of time. To make the timer appear as a countdown timer I take the absolute value of this result.

The rest is a matter of displaying the result as needed.