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 / Time calculation not t...
Power Apps
Answered

Time calculation not taking in mind hours

(0) ShareShare
ReportReport
Posted on by 88

Hello community,

 

I have a time calculation that doesn't work as I'd expect it to work:

I have a Start Date + Hour + Minutes and End Date + Hour + Minutes

I have this formula on a label at the bottom :
With(
{
days: RoundDown(DateDiff(dStart.SelectedDate, dEnd.SelectedDate, Hours) / 24, 0),
hours: Mod(RoundDown(DateDiff(Time(HourValue1.Selected.Value,0,0), Time(HourValue2.Selected.Value, 0,0), Minutes) / 60, 0), 24),
minutes: Mod(DateDiff(Time(HourValue1.Selected.Value,MinuteValue1.Selected.Value,0), Time( HourValue2.Selected.Value,MinuteValue2.Selected.Value,0), Minutes), 60)
},
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

But its not calculating correctly:
Start Time:

StanP_0-1659525130992.png

End Time:

StanP_1-1659525145262.png

Result:

StanP_3-1659525269829.png



Can anyone tell me where I m going wrong with this?

Regards,

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @StanP ,
    I tend to attack this another way as below

    With(
     {
     wStart: 
     dStart.SelectedDate + Time(
     Value(HourValue1.Selected.Value),
     Value(MinuteValue1.Selected.Value),
     0
     ),
     wEnd: 
     dEnd.SelectedDate + Time(
     Value(HourValue2.Selected.Value),
     Value(MinuteValue2.Selected.Value),
     0
     )
     },
     With(
     {
     wDays: 
     RoundDown(
     wEnd - wStart,
     0
     )
     },
     With(
     {
     wHours: 
     Mod(
     wEnd - wStart,
     wDays
     ) * 24
     },
     wDays & " Days," & 
     RoundDown(
     wHours,
     0
     ) & " Hours, " & 
     Mod(
     wHours,
     RoundDown(
     wHours,
     0
     )
     ) * 60 & " Minutes"
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @StanP ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • StanP Profile Picture
    88 on at

    Hey Warren,

     

    I solved the issue maybe 1 hour after I posted this here with this:

     


    With(
    { wTime:
    DateDiff(
    dStart.SelectedDate + Time(HourValue1.Selected.Value, MinuteValue1.Selected.Value, 0),
    dEnd.SelectedDate + Time(HourValue2.Selected.Value, MinuteValue2.Selected.Value, 0),
    Minutes)
    },
    RoundDown(wTime / 60,0) & " Hour(s) " &
    Mod(wTime,60) & "Minute(s)")

    But will accept your solution as it is a solution to the problem

    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 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard