cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JimmyWork
Super User
Super User

Time spent (Timer roundup minutes)

Hi

 

I'm trying to create the following.
- Timer starts when pressed.

- Timer Ends, roundup to minutes always and patch SharePoint column (Column named "TimeSpent").

- If timer starts again later on the same item I will take the current minutes saved in the column "TimeSpent" and add the new minutes and then patch.

 

Now first issue is a normal timer looks like it stops the time if you minimize the window. This was solved as following.

 

- StartButton

Set(StartTime, Now());
UpdateContext({StartTimer:true})

- Timer

OnTimerStart:
Set(Now, Now())

-TimerLabel Showing Time

Text(Time(0, 0, DateDiff(StartTime,Now,Seconds)), "[$-en-US]hh:mm:ss")

 The above will keep the time running even if you minimize the window and do something else.

 

Now what I want is to take the data from the TimerLabel and RoundUp to only minutes. (This is what i have issue with, dont know how to do this correctly)

 

Last step is to patch the SharePoint column with the minutes. This part is half done as i can patch the column but i cannot get only minutes and my other issue is if the item already have data in the column, for example the item has 55minutes stored, then i want to take the 55 and add the new minutes i just collected and patch it.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @JimmyWork ,

Based on my test, I add more label to display the value of “StartTime”, “Now” and “DateDiff” , and find that the DateDiff returns as 0:

v-albai-msft_0-1613963731079.png

So this is the issue. When DateDiff() uses two times that only has different seconds(with same minutes and hours), the result will return 0. This formula will work when the minutes(or hours) of the two times are different:

v-albai-msft_1-1613963731081.png

Per my test, you can use below formula:

RoundUp(DateDiff(StartTime,Now,Seconds)/60,0)

v-albai-msft_2-1613963731084.png

 

v-albai-msft_3-1613963731085.png

Best Regards,

Allen

View solution in original post

6 REPLIES 6
v-albai-msft
Community Support
Community Support

Hi @JimmyWork ,

Based on you description, I do a simple test for your reference.

I assume that: You have two button, one button for creating new item, the other button for updating TimeSpent value.

So I create a list with a Number column called “TimeSpent”:

v-albai-msft_0-1613558136218.png

Go to my app, set OnSelect property of Patch button to(this will create a new list item):

Patch(list2,Defaults(list2),{Title:DataCardValue1.Text,TimeSpent:RoundUp(Timer2.Value/60000,0)})

Set OnSelect property of Update button to(this will update the item whose Title is match the entered value):

Set(varItem,LookUp(list2,Title=DataCardValue1.Text));Patch(list2,varItem,{TimeSpent:varItem.TimeSpent+RoundUp(Timer2.Value/60000,0)})

v-albai-msft_1-1613558136223.png

You can also add some condition then add above two formula into one button, for example, if “DataCardValue1.Text in list2.Title”, lookup this item by Title, then update its value; if not, create a new list item.

Best Regards,

Allen

@v-albai-msft Thank you for answering but i cannot use the Timer value as the timer just repeats every second and on timer start i have Set(Now, Now()) then i use DateDiff to get the actual time spent, i do this because if you use a normal timer and minimize the browser the timer stops.

Hi @JimmyWork ,

So try to use below formula for Patch button:

Patch(list2,Defaults(list2),{Title:DataCardValue1.Text,TimeSpent:RoundUp(DateDiff(Now,Now(),Minutes),0)})

And below formula for Update button:

Set(varItem,LookUp(list2,Title=DataCardValue1.Text));Patch(list2,varItem,{TimeSpent:varItem.TimeSpent+RoundUp(DateDiff(Now,Now(),Minutes),0)})

Best Regards,

Allen

@v-albai-msft Thank you again

I dont know if i understand the RoundUp function wrong, as I have everything working but in my mind when the timer starts and it has gone 20sec then it should round up to 1min, and if the time has counted 1min, 9sec it should round up to 2min. It does not seem to do this, at least not if i create a label and have RoundUp(DateDiff(StartTime,Now,Minutes),0)

When i stop the timer it does not roundup

Hi @JimmyWork ,

Based on my test, I add more label to display the value of “StartTime”, “Now” and “DateDiff” , and find that the DateDiff returns as 0:

v-albai-msft_0-1613963731079.png

So this is the issue. When DateDiff() uses two times that only has different seconds(with same minutes and hours), the result will return 0. This formula will work when the minutes(or hours) of the two times are different:

v-albai-msft_1-1613963731081.png

Per my test, you can use below formula:

RoundUp(DateDiff(StartTime,Now,Seconds)/60,0)

v-albai-msft_2-1613963731084.png

 

v-albai-msft_3-1613963731085.png

Best Regards,

Allen

@v-albai-msft Thank you so much for the help 🙂

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,317)