web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

Duration Timing

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

I have created an audit app using PowerApps. I have not been able to figure out how to automatically time how long it takes the auditor to complete the audit. I would like the app to start timing when the audit form is opened and then stop timing when the submit button is selected.  I would then like the duration data to populate into a column in the SharePoint list where the rest of the audit data is collected. Anyone know how to do this?

Categories:
I have the same question (0)
  • Mr-Dang-MSFT Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

    You will want to learn about the timer control:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-timer

     

    Timers have an AutoStart property where you can place a condition on when it should be starting. Accordingly, they will stop when the same condition is false.

     

    You can give a timer a very long duration so they do not end before the audit is complete.

     

    When you write the data back to SharePoint, you would save Timer1.Value. That returns the elapsed time in milliseconds. If you prefer seconds, divide Timer1.Value/1000. If you would like the time formatted in hh:mm:ss, then you could use the Time() function:

    Time(0,0,Timer1.Value/1000)

    It will regroup all the seconds into h and m accordingly. Saving that format would need a text column in SharePoint though.

  • BenFetters Profile Picture
    on at

    Hi,

     

    I have an idea that hopefully can help. Please let me know if you have questions because I know explanations can be kind of confusing!

     

    First, I would add a timer to the screen that you have the form on. Then set the timer's "AutoStart" property to true. Then, on the form there is an "OnSuccess" property - set this to this formula: Patch(YourDataSourceName, YourFormName.LastSubmit, {Duration: Timer1.Text})  you might need to say Value(Timer1.Text) depending on what the type of field it is.

     

    Lastly, for your submit button, be sure to add this formula to the END of the "OnSelect" property: Reset(Timer1)

     

    I hope this makes sense and was helpful.

     

    Ben

     

     

  • Verified answer
    timl Profile Picture
    37,283 Super User 2026 Season 2 on at

    Hi Guys,

     

    I'm just curious as to why we think it's necessary to use a timer here?

    Could we not just store the time that the user opens the screen into a variable (eg on the OnVisible property of the screen)? Then on the Submit button, we can work out the duration by calculating the difference between the current time and the initial time.
    @Anonymous - if you're really stuck with implementing the timer technique that that @Mr-Dang-MSFT and @BenFetters describes, I can probably give you a fuller explanation of what I described above.

  • Mr-Dang-MSFT Profile Picture
    Microsoft Employee on at

    @BenFetters, I like how you also described how to restart the timer.

     

    @timl, now that I think about it, I like the idea of saving the start time and end time, then calculating the elapsed time later. That is more manageable and provides clearer information.

     

    @Anonymous, if you want to go with Tim's method, you can brush up on DateDiff.

    Here's a primer on using DateDiff for counting down:

    https://www.youtube.com/watch?v=eS4HesPcOSk

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @BenFetters, @timl, @mr-dang-MFST,

     

    Thank you for all the great suggestions. It sounds like saving the start and end time and then calculating the elapsed time later may be the best option. If you have any suggestions on how to set this up I would appreciate it. Watching the suggested utube video now.

  • u4jaanus Profile Picture
    on at

    Hi, 

    I have somewhat similar problem; however my scenerio is little different. I got my duration fine by using DateDiff. However I am unable to figure out how to add up 2 or more Durations. i.e. if I go on my Break. I am pressing a Button which starts a timer and then once I am back I hit that button again. It Stops the timer and now I have 2 variables for Break Start and Stop which then I use to calculate the duration of my break using DateDiff. Now the tricky part begins. I want to record another break and add the result in previous duration of break to get total time I was on break in whole day. Regardless of how many times I went on break. 

    I am unable to think it through properly; would really appreciate your advise.

  • BenFetters Profile Picture
    on at

    So to sort of briefly explain how I would do that, is I would have a the fields: BreakStarted (Date & Time field), OnBreak (Yes/No field), and a TotalBreakTime (Number field). Then, all you have to do is when you go on break, you set the BreakStarted = Now(), OnBreak = true. Then when you come back from the break, you would set OnBreak = false, and TotalBreakTime = Previous Break Time + Value(DateDiff(BreakStarted,Now(),Minutes)/60) - This way, you just add the 15 minutes of break time you just went on to the previous 15 minutes you already had.

     

    Lastly, when you want to get your total time, you would just subtract the ending time from the start time and then subtract the TotalBreakTime from that. 

     

    That is a simplified explanation but if it didn't make any sense or you would like more clarification just let me know! 

     

    Kind regards,

     

    Ben Fetters

  • u4jaanus Profile Picture
    on at

    Hi Ben,

    Thanks; this is not exactly what i am looking for but I got my problem sorted. Used Collections store break durations and then in the end Sum them up to get total value.

    Thanks.

    ------- 

    I have another situation here. I have few people which went on break but then if I go to their record and put them on break on changing / selecting someone else record trigger resets its self. In short app is not keeping its state for individual records. Also I can see variable value of one persons form in a different person. (forms are using same variables though). I think I need to look into Global and local variables if there is any. Any suggestion?

  • BenFetters Profile Picture
    on at

    Oh okay, I'm glad your figured out a good solution! And for the other situation, I try throwing some labels on your screen or screens and setting them to the different variables just so you can see things a little more clearly to try to find the problem. Then running through the process and looking for all the different places where the variable is changing or staying the same when it should change? I'm not sure what the problem could be though. But putting labels on the screen always helps me alot as well as testing the app on your phone if you can. Sometimes it works a little differently on the phone. I'll let you know if I think of something else though! 

  • u4jaanus Profile Picture
    on at

    Hi, Thanks for replying.

    It is always Good to talk I may find a solution 🙂

     

    Scenerio is.. I have a list screen showing all people working, then if click on each person i can see their start time and then have trigger to go on break and to finish working. Point to note is.... I have 2 total screens created 1 screen with LIST of people from sharepoint. 2nd screen to FORM where that persons "More Details" are showing. Some feilds which are fetching data from Sharepoint I have set them as View only. Some Text fields which can take data are edit. i.e. Breaks, durations etc. 

    When I trigger a breakstart event on one persons form page and then go back on list screen and click to another person; it reset the trigger (Toggle) on the previous person break. And anything in the variables/collections which was triggered/populated during the calculation of previous person still shows on new person form page.

    Hope I am making more sense now.

     

    It is like; 1 form page is being used for every person along with the variables. so Question would be how can i make forms and its variables attach to its parent in list. I am not sure if this is even possible in Powerapps with the approach i m using.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#2
11manish Profile Picture

11manish 205 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard