Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

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

Like (0) ShareShare
ReportReport
Posted on 15 Feb 2022 13:46:52 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:
  • Community Power Platform Member Profile Picture
    on 16 Feb 2022 at 05:38:55
    Re: Date And Time difference with date, hours and minutes including AM/PM

    Hey @RandyHayes , Thanks for replying.

    Yes This works for me

     

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 15 Feb 2022 at 15:53:01
    Re: Date And Time difference with date, hours and minutes including AM/PM

    @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.

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on 15 Feb 2022 at 14:51:30
    Re: Date And Time difference with date, hours and minutes including AM/PM

    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!

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard
Loading started
Loading started