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.
Solved! Go to Solution.
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:
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:
Per my test, you can use below formula:
RoundUp(DateDiff(StartTime,Now,Seconds)/60,0)
Best Regards,
Allen
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”:
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)})
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:
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:
Per my test, you can use below formula:
RoundUp(DateDiff(StartTime,Now,Seconds)/60,0)
Best Regards,
Allen