cancel
Showing results for
Did you mean:
Resolver I

Hi

I have a scenerio where I got my duration between 2 timestamps using Now() and by using DateDiff. However I am unable to figure out how to add 2 or more Durations. i.e. if I go on my Break. I am pressing a Button which creates a Variable and TimeStamp using now() function and then once I am back I hit that button again and it creates another Vairable with TimeStamp using Now() function. 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 for me. I want to record another break and ADD or SUM the result with previous calculated 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.

6 REPLIES 6
Super User

The way I would do this would be to store the duration that you've calculated using DateDiff into a collection.

On your stop button, you can include the following formula to collect the minutes into a collection:

`Collect(durations, {mins:30})`

Here, you would obviously substitute 30 with the value you've calculated.

To retrieve the total value, you can call the Sum function to calculate the total duration.

`Sum(durations, mins)`

Resolver I

I tried Collect as you suggested. However it only works if Data is Number type .i.e 4,5,6, but if data is in Time format say. 00.00.05, 00.00.10. it wont show any result if I sum it.

here is the part of the code.

UpdateContext({Dur:Text(Time(0,0,DateDiff(BreakStart,BreakEnd,Seconds)),"[\$-en-US]hh:mm:ss")}) && Collect(Duration,{BreakTimes: Dur}).

If I use only DateDiff the answer would be only in seconds and Collect works fine  as it is in number format.

I think I would need to check how to read Text Time format data from collection and then sum it.

What would you suggest.

Super User

My suggestion would be to collect the durations in seconds or minutes. If you want to display the result in hh:mm:ss or some other format, you can write a formula to display your result in the desired format.

The formula you would use would divide by 60 and use the Mod function.

You can probably adapt the answer here to produce the output format that you want.

https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/Displaying-date-difference-in-both-h...

Community Support

Hi @u4jaanus ,

Do you want to store a Text time value into a Collection rather than a Number value (minutes)?

Based on the needs that you mentioned, I think the ForAll function and Split function could achieve your needs. I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the "Break Stop" button to following:

`UpdateContext({Dur: Text(Time(0,0,DateDiff(BreakStart,BreakEnd,Seconds)),"[\$-en-US]hh:mm:ss")});Collect(Duration, {BreakTimes: Dur})`

Add a Label in your app, set the Text property to following:

```Sum(                              /* <-- Return total Duration in Seconds unit */    ForAll(
Duration,
Last(Split(BreakTimes, ":")).Result + Last(FirstN(Split(BreakTimes, ":"),2)).Result * 60 + First(Split(BreakTimes, ":")).Result * 60 * 60
),    Value)```

If you want to return the Total duration in Minutes unit, please modify above formula as below:

```Sum(                              /* <-- Return total Duration in Seconds unit */    ForAll(
Duration,
Last(Split(BreakTimes, ":")).Result/60 + Last(FirstN(Split(BreakTimes, ":"), 2)).Result + First(Split(BreakTimes, ":")).Result * 60
),    Value)```

Please take a try with above solution, then check if the issue is solved.

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Resolver I

Can I ask why you didnt use Last(FirstN(Split(BreakTimes, ":"),2) to access all 3 split values by chaing 2 to 1 and 3 you can access all 3?

Further I have tried this approach; the answer I got while testing for 72seconds to minutes was 1.2 which is in decimal format and not suited. Tried spending sometime to convert the decimal to time format seams like no easy way around it.

Resolver I

Update:

Okay I couldnt do the sum and keep my Time format. So I decided to go with number format.

I used Collections and then Sum.

If i use Text(time(0,0,Diffdate()),[en-US]00:00:00) format and add to collection it adds in text format... but then when i want to add it i couldnt do it. so reverted to simple number format which is not what i wanted.

I have another problem now. not sure if I should open another post for that one. but will take advise on this.

I have number of peoples assigned to different tasks who I can access from a list in Form Edit mode. Now when I add a Break Start for one user and gets out of the form and goes to another user I can see previous form varables values. In short Variables I have are kind of global not different instances of labels with each form. I believe this is because I am using same 1 form to view and perform calculation on the data. I need a child form of each parent from list; so could run calculation on each form independtly of other. What should be the approach here please; I really hope I dont have to save all the data to sharepoint before moving away each time?

Announcements

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Top Kudoed Authors
Users online (4,687)