cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Hoo to get Datediff return Hours and Minutes

Hello,

 

I am building a very simple app to track overtime (timesheet basically). I currently have 2 text inputs, a start time and an end time. Both input's have this format yyyy-mm-dd hh:mm.

 

I then I have a 3rd input that is readonly where I want it to calculate the difference between the 2 dates in hours and minutes. This is what I have at the moment. 

 

Text( 
    DateDiff( DateTimeValue(Start_time_input.Text), DateTimeValue(End_time_input.Text), Hours),
"[$-en-US] 00.00")

 

 

With this formula I am only hours hours and not the minutes. For example: 

 

Start time: 2019-06-11 10:00
End time:  2019-06-11 12:30

Expected results: 02.50 

Powerapps results: 2

 

Would anyone know how to go about this?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi @Owizardo ,

Based on the needs that you mentioned, I have made a test on my side, please consider take a try with the following workaround:

8.JPG

 Set the Text property of the Label to following:

If(
    Len(Text(DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours)))=1,
    "0" & DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours),
    DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours)
 ) & "." & Right(Text(Round(DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Minutes)/60, 2)), 2)

On your side, you may need to type the following formula:

If(
    Len(Text(DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours)))=1,
    "0" & DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours),
    DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours)
 ) & "." & Right(Text(Round(DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Minutes)/60, 2)), 2)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Dual Super User III
Dual Super User III

DateDiff will only return whole numbers.  You need to get it to return the value in minutes and then do some math to calculate the hours and minutes.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted

Ok thanks, changed up my formula to: 

 

Text(
    DateDiff( DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Minutes) / 60
, "[$-en-US]00.00")

 

Seems to be working better.  Would you know how to go about rounding off tot he closest 5 mins?

Highlighted

Hi @Owizardo ,

Based on the needs that you mentioned, I have made a test on my side, please consider take a try with the following workaround:

8.JPG

 Set the Text property of the Label to following:

If(
    Len(Text(DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours)))=1,
    "0" & DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours),
    DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Hours)
 ) & "." & Right(Text(Round(DateDiff(DateTimeValue(TextInput2.Text), DateTimeValue(TextInput3.Text), Minutes)/60, 2)), 2)

On your side, you may need to type the following formula:

If(
    Len(Text(DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours)))=1,
    "0" & DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours),
    DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Hours)
 ) & "." & Right(Text(Round(DateDiff(DateTimeValue(TextInput5.Text), DateTimeValue(TextInput5_1.Text), Minutes)/60, 2)), 2)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (11,792)