web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Date And Time differen...
Power Apps
Answered

Date And Time difference with date, hours and minutes including AM/PM

(0) ShareShare
ReportReport
Posted on by

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:

Tiksha_0-1644932094378.pngTiksha_1-1644932152539.pngTiksha_2-1644932237020.png

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

Categories:
I have the same question (0)
  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    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!

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Tiksha 

    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.

  • Community Power Platform Member Profile Picture
    on at

    Hey @RandyHayes , Thanks for replying.

    Yes This works for me

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard