cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Phu_Le
Level: Powered On

compare last time and current time

Hi, I design a Powerapps that scan check-in and scan check-out for the user

So how to get the last time of scan for the current user and compare the last time check of this user with the current time. Please help me solve this problem, I am just studying to write Powerapps. Thanks!

Capture.PNGSharepoint List View

3 ACCEPTED SOLUTIONS

Accepted Solutions
hnguy71
Level 8

Re: compare last time and current time

HI @Phu_Le ,
You can most likely get current user's latest scan time by creating a variable or label. Something along the lines of this:

UpdateContext({LatestEntry:Filter(First(Sort(TABLE_SOURCE, 'Scan Time', Descending)), 'Employee Name'.FullName = User().FullName})

From there you can do your comparison:

If(LatestEntry = Now(), DO SOMETHING, ELSE DO SOMETHING ELSE)

View solution in original post

Super User
Super User

Re: compare last time and current time

Hi @Phu_Le , 

 

This expression fetches the most recent Scan time record from the sharepoint list. Here I used User().FullName to get current user's Name and filter results on Scan Time.
First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending))MicrosoftTeams-image (62).png

 

To for get the difference between the last entry in the record and current time, used the expression:
"Date Diff: "& DateDiff(ThisItem.'Scan Time',Now(),Hours)
Since, I have used the control inside gallery, so directy referenced with the ThisItem.'Scan Time'.MicrosoftTeams-image (63).png

 

If you want to use it outside the gallery control on some label. Use below expression:
"Date Diff: "& DateDiff(First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending)).'Scan Time',Now(),Hours)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

Super User
Super User

Re: compare last time and current time

@Phu_Le 

 

You can set the status using below formula:
If(DateDiff(ThisItem.'Scan Time',Now(),Hours) >= 11.5,"OUT","IN")
 
Hope this Helps!

View solution in original post

11 REPLIES 11
hnguy71
Level 8

Re: compare last time and current time

HI @Phu_Le ,
You can most likely get current user's latest scan time by creating a variable or label. Something along the lines of this:

UpdateContext({LatestEntry:Filter(First(Sort(TABLE_SOURCE, 'Scan Time', Descending)), 'Employee Name'.FullName = User().FullName})

From there you can do your comparison:

If(LatestEntry = Now(), DO SOMETHING, ELSE DO SOMETHING ELSE)

View solution in original post

Super User
Super User

Re: compare last time and current time

Hi @Phu_Le , 

 

This expression fetches the most recent Scan time record from the sharepoint list. Here I used User().FullName to get current user's Name and filter results on Scan Time.
First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending))MicrosoftTeams-image (62).png

 

To for get the difference between the last entry in the record and current time, used the expression:
"Date Diff: "& DateDiff(ThisItem.'Scan Time',Now(),Hours)
Since, I have used the control inside gallery, so directy referenced with the ThisItem.'Scan Time'.MicrosoftTeams-image (63).png

 

If you want to use it outside the gallery control on some label. Use below expression:
"Date Diff: "& DateDiff(First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending)).'Scan Time',Now(),Hours)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

Community Support Team
Community Support Team

Re: compare last time and current time

Hi @Phu_Le  @yashag2255  @hnguy71 

 

Thanks for your posts and solutions.

These would be helpful for uses  who have same issues.

 

Best Regards.

Yumia

Phu_Le
Level: Powered On

Re: compare last time and current time

Hi  @hnguy71  & @yashag2255

Thank for your help, I have one more question, please help.

 

I would like to compare LastEntry Time with Now(), I already have a variance: Status

My idea is: If LastEntry +11,5 hours >= Now Then Status = "OUT"

Else Status= "IN". Please guide me on how to compare time for this case. Thank!

 

Capture.PNG

Super User
Super User

Re: compare last time and current time

@Phu_Le 

 

You can set the status using below formula:
If(DateDiff(ThisItem.'Scan Time',Now(),Hours) >= 11.5,"OUT","IN")
 
Hope this Helps!

View solution in original post

Phu_Le
Level: Powered On

Re: compare last time and current time

Thank @yashag2255, It is work smoothly!

 

Now I would like to lookup value from this SharePoint List

I already set up some variances in Edit view: 

Employee Name is EmpName

Lap Top is LapTop

Department is Dept

So how can I look up those value form last result in SharePoint list, base on Barcodescanner.value = "VN10-1DLCZE5"

It's mean: If Barcodescanner.value = "VN10-1DLCZE5" then, LapTop=...., Dept=....., EmpName=..... (lookup from SharePoint list). Many Thanks!

 

Capture1.PNG

 

Capture.PNG

 

Super User
Super User

Re: compare last time and current time

@Phu_Le 

 

Try this:

 

If(Barcodescanner.value = "VN10-1DLCZE5",LapTop=First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending)).'Lap Top', Dept=First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending)).Department, EmpName=First(Sort(Filter('Laptop Security Check',Title = User().FullName),'Scan Time',Descending)).'Employee Name')
Phu_Le
Level: Powered On

Re: compare last time and current time

Hi  @yashag2255

Thank for helping me those questions, I still have some gaps to do my app, please support. Mayny Thanks

I have a DropBox (["SHIFT1","SHIFT2","SHIFT3"]

How to make this Dropbox auto chose the right SHIFT, depend on the Now() time

IF       06:30 AM  >=  Now()  >  02:30 PM => SHIFT 1

IFElse 02:30 PM  >=   Now()  > 10:30 PM => SHIFT 2

Else => SHIFT 3

Super User
Super User

Re: compare last time and current time

Hey @Phu_Le 

 

Can you try using this expression::

 

If(TimeValue(Text( Now(), "[$-en-US]hh:mm" )) >= TimeValue("6:30") && TimeValue(Text( Now(), "[$-en-US]hh:mm" )) < TimeValue("14:30"),"SHIFT1",TimeValue(Text( Now(), "[$-en-US]hh:mm" )) >= TimeValue("14:30") && TimeValue(Text( Now(), "[$-en-US]hh:mm" )) < TimeValue("22:30"),"SHIFT1","SHIFT3")

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 136 members 3,196 guests
Please welcome our newest community members: