Hello All,
I'm unable to get the exact calculation of date and time difference even after searching alot.
What I want is to calculate date and time difference which returns me data in Date, Hours and Minutes(optional) But want to calculate it with AM/PM included:
I request you to please review my code where I'm lacking:
Ineed to calculate the time difference when including AM/PM.How I leverage this at in this code
OnSelect of StartDate
Set(_timedifference,With({wTime:DateDiff(Time(Value(drpFromHrs.Selected.Value),Value(drpFromMin.Selected.Value),0),Time(Value(DrpToHrs.Selected.Value),Value(drpToMin.Selected.Value),0),Minutes)},RoundDown(wTime/60,0)&"Hrs :"&Mod(wTime,60)&" Min"));
Thanks in advance
I would suggest just converting the date and time values as they are entered in your controls and ignore worrying about the AM and PM. PowerApps will perform the conversions you need automatically.
The following formula will give you the hours and minutes between your two entered date/times.
With({lclminutes:
DateDiff(
DateTimeValue(fromDatePicker.SelectedDate & " " & drpFromHrs.Selected.Value & ":" & drpFromMin.Selected.Value & " " & drpFromAMPM.Selected.Value, "en-US"),
DateTimeValue(toDatePicker.SelectedDate & " " & drpToHrs.Selected.Value & ":" & drpToMin.Selected.Value & " " & drpToAMPM.Selected.Value, "en-US"),
Minutes
)
},
RoundDown(lclminutes/60, 0) & ":" & Text(Mod(lclminutes, 60), "00")
)
Replace the names of your controls in the above formula and you should get what you are looking for.
I hope this is helpful for you.
The easir way might be converting the "PM" to 24 format... If it is 1 = 13, 2= 14, and so on...
You can use a switch to do that...
After that, a DateDiff will do the work
If you need additional help please tag me in your reply and please like my reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️!
Best regards,
Gonçalo Nogueira
Check my LinkedIn!
Buy me a coffee!
Check my User Group (pt-PT)!
Last Post on Community
My website!
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional