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 / How to get time differ...
Power Apps
Answered

How to get time difference between two start time and end time.

(0) ShareShare
ReportReport
Posted on by 88

Hi, I have four drop downs , which stores hours and minutes of start and end.

which is as shown below FIRST and LAST fields.

Suchithra_A_0-1593947055432.png

Now I want to calculate difference between hours and minutes.

I have used below formula on default property of text field (No of hours) to calculate number hours.

Text(((HourValue2.Selected.Value*60+MinuteValue2.Selected.Value)-( HourValue1.Selected.Value*60+MinuteValue1.Selected.Value))/60,"[$-en-US]###.00")

 

Suchithra_A_1-1593947252615.png

 

where hours is calculating properly. But minutes is not calculating exactly.

Kindly help me to exact time difference.

 

 

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @Suchithra_A 
    You can use the DATEDIFF function to accomplish this goal without complicated calculations

    DateDiff(
     Time(HourValue2.Selected.Value, MinuteValue2.Selected.Value,0)
     Time(HourValue1.Selected.Value, MinuteValue1.Selected.Value,0),
     Hours
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

  • Suchithra_A Profile Picture
    88 on at

    @mdevaney 

     

    This is not working for me.Facing Below error.

     

    "Invalid argument type(Text). Expecting Number Value instead."

    Suchithra_A_0-1594013051457.png

     

    I tried the formula

      Value(DateDiff(
    Time(Value(HourValue2.Selected.Value), Value(MinuteValue2.Selected.Value),0)
    Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value),0),
    Hours))

    This is also not working.

    Please help me to fix this.

     

  • Suchithra_A Profile Picture
    88 on at

    Hi,

    I have modified the formula to 

    Value(DateDiff((DateValue2_2.SelectedDate + Time(Value(HourValue2_2.Selected.Value), Value(MinuteValue2_2.Selected.Value), 0)),
    (DateValue1_2.SelectedDate + Time(Value(HourValue1_2.Selected.Value), Value(MinuteValue1_2.Selected.Value), 0)),Hours))

     

     

    Here time is calculating only in terms of number hours.

    I want in both hours and minutes .

    Example :

    Suchithra_A_0-1594111280146.png

    I want No: of hours as "2:30".

     

     

    Anyone please guide me.

  • mdevaney Profile Picture
    29,989 Moderator on at

    @Suchithra_A 
    Please try this code.  If you are getting an error please share the error message.

    DateDiff(
     Time(Value(HourValue2.Selected.Value), Value(MinuteValue2.Selected.Value,0))
     Value(Time(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value,0)),
     Hours
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Suchithra_A Profile Picture
    88 on at

    @mdevaney 

    Still getting error: 

    "we expect text at this point of formula"

    Suchithra_A_0-1594183389779.png

     

  • Verified answer
    mdevaney Profile Picture
    29,989 Moderator on at

    @Suchithra_A 

    You are getting an error because you did not specify the date format in the 2nd argument of the TEXT function.

    Text(
     DateDiff(
     Time(Value(HourValue2.Selected.Value), Value(MinuteValue2.Selected.Value,0))
     Value(Time(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value,0)),
     Hours
     ),
     ShortDateTime
    )


    Link to TEXT function MS documentation:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-text

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • mdevaney Profile Picture
    29,989 Moderator on at

    @Suchithra_A 
    Did I answer your question?  If yes, please come back and Accept As Solution.

  • Suchithra_A Profile Picture
    88 on at

    @mdevaney  Thanks for your response ,

     

    With that formula also I am getting same error.

     

    But , I am getting expected answer with the below formula:

    Concatenate(
    Text(
    DateDiff(
    DateValue1.SelectedDate +
    Time(
    Value(HourValue1.Selected.Value),
    0, 0),
    DateValue2.SelectedDate +
    Time(
    Value(HourValue2.Selected.Value),
    0, 0),
    Hours),"[$-en-US]##"),

    ":",

    Text(
    If(
    DateValue2.SelectedDate > DateValue1.SelectedDate,
    DateDiff(
    DateValue1.SelectedDate +
    Time(0, Value(MinuteValue1.Selected.Value), 0),
    DateValue2.SelectedDate +
    Time(0, Value(MinuteValue2.Selected.Value), 0),
    Minutes) / 60,

    DateDiff(
    DateValue1.SelectedDate +
    Time(0, Value(MinuteValue1.Selected.Value), 0),
    DateValue2.SelectedDate +
    Time(0, Value(MinuteValue2.Selected.Value), 0),
    Minutes)
    )
    )
    )

     

    Thanks

  • ThorPower Profile Picture
    2 on at

    Time.png

    "Value(Value(HourValue2.Selected.Value) - Value(HourValue1.Selected.Value)) & "h" & Abs(Value(Value(MinuteValue2.Selected.Value) - Value(MinuteValue1.Selected.Value))) & "min" '

     

    I calculated the hours separate and minutes separate

  • Pkeskar Profile Picture
    16 on at

    This works for hour and time. How would I include day in this function? 

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