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 Apps
Answered

Time Difference

(1) ShareShare
ReportReport
Posted on by 728

Hi

 

I am trying to calculate the time difference.  I have the following formula on a label:

 

DateDiff(DateTimeValue(ThisItem.StartTime),DateTimeValue(ThisItem.EndTime),Hours)

 

But it only shows the number of hours and not the minutes.  For example,  I have a start time and end time, if start time is 08:00 and end time is 12:30, the label displays 4.

 

How can i get it to show 4 hours 30 mins (4.5)

 

The labels are in a gallery which is connected to a collection.

 

thanks

Categories:
  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @neill_long 

     

    Convert Minutes to either "X Hours Y Minutes" or "X.Y hours"

     

    For example, to convert it to "X Hours Y Minutes" 

     

     

    With
    (
     {st:DateTimeValue(ThisItem.StartTime),et:DateTimeValue(ThisItem.EndTime)}
     ,DateDiff(st,et,Hours) & " hours " & Mod(DateDiff(st,et,Minutes),60) & " mins"
    )

     

     

    and to convert it to "X.5 hours" 


    With
    (
     {st:DateTimeValue(ThisItem.StartTime),et:DateTimeValue(ThisItem.EndTime)}
     ,Text(DateDiff(st,et,Minutes)/60 ,"#.#")
    )

     

    and for both at the same time:

    With
    (
     {st:DateTimeValue(ThisItem.StartTime),et:DateTimeValue(ThisItem.EndTime)}
     ,With
     (
     {dh:DateDiff(st,et,Hours),dm:DateDiff(st,et,Minutes)}
     ,dh & " hours " & Mod(dm,60) & " mins" & " (" & Text(dm,"#.#") & ")"
     )
     
    
    )

     

    Check if it helps @neill_long 

  • SphesihleSibiya Profile Picture
    81 on at

    Hi @neill_long,

     

    Try This:

    The Mod operation should give you the remainder in minutes since there is 60 minutes in an hour

    DateDiff(DateTimeValue(ThisItem.StartTime),DateTimeValue(ThisItem.EndTime),Hours) & " hours " & Mod(DateDiff(DateTimeValue(ThisItem.StartTime),DateTimeValue(ThisItem.EndTime),Minutes),60) & " Minutes"
  • Verified answer
    victorcp Profile Picture
    2,350 Moderator on at

    Hi,

    you have to get the difference in minutes instead of hours, and then do the necessary calculations.

     

    Here are two examples to achieve what you want:

    victorcp_4-1665047071638.png

    RoundDown(DateDiff(Today(),Now(),Minutes)/60,2)

     

    victorcp_3-1665047054200.png

    With({time:DateDiff(Today(),Now(),Minutes)}, RoundDown(time/60,0) & " hours "& Mod(time,60)) & " min"

    With function is used to create a variable (time) that works inside its scope.

     

    Hope it helps 🙂

     

     

     

     

  • neill_long Profile Picture
    728 on at

    thanks everyone for your help, all great suggestions.  Went with:

     

    RoundDown(DateDiff(ThisItem.StartTime,ThisItem.EndTime,Minutes)/60,2)

     

    Works great.

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

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard