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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / DateDiff formula not w...
Power Apps
Answered

DateDiff formula not working

(0) ShareShare
ReportReport
Posted on by

Hi All,

 

I am building an app and trying to calculate Total Hours out from (Time: Left Depot, Time: Arrival on Site, Time: Off Site, Time: Arrive at Depot)

 

Below is my formula and obviously something is wrong with the formula as it is not calculating the Total hour correctly.

 

Any help would be greatly apricated. 

 

kanwals360_1-1711017133866.png

 

 

 

Abs(
    DateDiff(
        DateTimeValue(Text(DateValue1.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue1.Selected.Value, "00") & ":" & Text(MinuteValue1.Selected.Value, "00")),
        DateTimeValue(Text(DateValue2.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue2.Selected.Value, "00") & ":" & Text(MinuteValue2.Selected.Value, "00")),TimeUnit.Hours
    )
) +
Abs(
    DateDiff(
        DateTimeValue(Text(DateValue2.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue2.Selected.Value, "00") & ":" & Text(MinuteValue2.Selected.Value, "00")),
        DateTimeValue(Text(DateValue3.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue3.Selected.Value, "00") & ":" & Text(MinuteValue3.Selected.Value, "00")),
        TimeUnit.Hours
    )
) +
Abs(
    DateDiff(
        DateTimeValue(Text(DateValue3.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue3.Selected.Value, "00") & ":" & Text(MinuteValue3.Selected.Value, "00")),
        DateTimeValue(Text(DateValue4.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue4.Selected.Value, "00") & ":" & Text(MinuteValue4.Selected.Value, "00")),
        TimeUnit.Hours
    )
) +
Abs(
    DateDiff(
        DateTimeValue(Text(DateValue4.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue4.Selected.Value, "00") & ":" & Text(MinuteValue4.Selected.Value, "00")),
        DateTimeValue(Text(DateValue1.SelectedDate, "[$-en-US]yyyy-mm-dd") & " " & Text(HourValue1.Selected.Value, "00") & ":" & Text(MinuteValue1.Selected.Value, "00")),
        TimeUnit.Hours
    )
)
Categories:
  • AllanDeCastro Profile Picture
    412 Most Valuable Professional on at

    Hello,

    It's difficult to answer this question without proper testing, but here's my attempt 🙂

    Abs(
     DateDiff(
     DateTimeValue(DateValue1.SelectedDate & " " & Text(HourValue1.Selected.Value, "00") & ":" & Text(MinuteValue1.Selected.Value, "00")),
     DateTimeValue(DateValue2.SelectedDate & " " & Text(HourValue2.Selected.Value, "00") & ":" & Text(MinuteValue2.Selected.Value, "00")),
     Hours
     )
    ) +
    Abs(
     DateDiff(
     DateTimeValue(DateValue2.SelectedDate & " " & Text(HourValue2.Selected.Value, "00") & ":" & Text(MinuteValue2.Selected.Value, "00")),
     DateTimeValue(DateValue3.SelectedDate & " " & Text(HourValue3.Selected.Value, "00") & ":" & Text(MinuteValue3.Selected.Value, "00")),
     Hours
     )
    ) +
    Abs(
     DateDiff(
     DateTimeValue(DateValue3.SelectedDate & " " & Text(HourValue3.Selected.Value, "00") & ":" & Text(MinuteValue3.Selected.Value, "00")),
     DateTimeValue(DateValue4.SelectedDate & " " & Text(HourValue4.Selected.Value, "00") & ":" & Text(MinuteValue4.Selected.Value, "00")),
     Hours
     )
    ) +
    Abs(
     DateDiff(
     DateTimeValue(DateValue4.SelectedDate & " " & Text(HourValue4.Selected.Value, "00") & ":" & Text(MinuteValue4.Selected.Value, "00")),
     DateTimeValue(DateValue1.SelectedDate & " " & Text(HourValue1.Selected.Value, "00") & ":" & Text(MinuteValue1.Selected.Value, "00")),
     Hours
     )
    )

     

    I removed unnecessary text formatting for the date portion (Text(DateValue.SelectedDate, "[$-en-US]yyyy-mm-dd")). If you use SelectedDate, it's already in a format that DateTimeValue can recognize.

    Try to ensure that the date and time values are selected correctly by users (DateValue.SelectedDate, HourValue.Selected.Value, and MinuteValue.Selected.Value), as any incorrect input might lead to unexpected results. Also, make sure the order of the dates and times aligns with your intended calculation.

     

  • Verified answer
    tligier Profile Picture
    7 on at

    Hi,

     

    I think the error here is that you are adding time between your 4th value and your first which is effectively doubling the total time.

    Also you are calculating the times between each values. If you know that the times will start with Time: Left Depot and end with Time: Arrive at Depot, you could calculate only the time between these 2 values.

     

    Best regards

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 432 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 347

#3
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

Last 30 days Overall leaderboard