Power Apps Timer Output Formatting
Do you need to get the value of a timer control to use in your Power Apps? Perhaps you want to keep track of how long it’s taking your users to fill out a form for example. In this post, I’ll show how you can put that timer value into a more user friendly format.
Default Timer Control Behavior
When you’re using a timer control, the timer output is stored in milliseconds like you see here:
It probably isn’t ideal to have that value stored in this format. Typically you would want to see this in Hours, Minutes and Seconds format. Like we see here:
Outputting in Hours, Minutes, Seconds Format
To get the Timers Value outputted in this format, you can use the following Formula:
With(
{
seconds: RoundUp(Timer1.Value/1000,1)
},
With(
{
minutes: RoundDown(seconds / 60,0),
secondsRemaining: Mod(
seconds,
60
)
},
With(
{hours: RoundDown(minutes / 60,0)},
hours & " hour(s) " & minutes & " minute(s) " & secondsRemaining & " second(s)"
)
)
)
This uses the new(ish) With() function in Power Apps to help do some math. First, you need to get the number of seconds in the timer which you can do using the RoundUp function and passing in the Timers value. You will take that calculation to then get the minutes and you’ll take the minutes to get the hours.
If you’d prefer a video walk through of this check out my YouTube Video:
Hi April,
it’s always interesting following your blog.
Just one comment in case the timer runs more than hour, the correct formula would be: hours & ” hour(s) ” & (minutes-(hours*60)) & ” minute(s) ” & secondsRemaining & ” second(s)”.
Another option would be to restructure it in this way: With({seconds:RoundUp(Timer1.Value/1000,1)},With({hours:RoundDown(seconds/3600,0),timeRemaining:Mod(seconds,3600)},With({minutes:RoundDown(timeRemaining/60,0),secondsRemaining:Mod(seconds,60)},hours&” hour(s) “&minutes&” minute(s) “&secondsRemaining&” second(s)”)))
Thanks Sergio