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 / Displaying date differ...
Power Apps
Unanswered

Displaying date difference in both hours and minutes

(0) ShareShare
ReportReport
Posted on by

I have two dates, declared as StartDate and EndDate. I can display the difference between each date in either hours or minutes, but I can not figure out how to display both hours and the remaining minutes. 

 

For example, f the StartDate is the 1st April 2019 at 1:00 am and EndDate is the 2nd of April 2019 at 1:30 am, I want it to calculate the difference as 24 hours and 30 mins rather than rounding to the nearest hour with the DateDiff function.

 

This is the formula in use: DateDiff(txtStartDate.SelectedDate, txtEndDate.SelectedDate, Hours)

 

Any help would be appreciated!

Categories:
I have the same question (0)
  • Verified answer
    CarlosFigueira Profile Picture
    on at

    You can use the DateDiff function twice, one for the hours and one for the minutes, and take the value of the minutes modulus 60 (to get only the minutes part), like in the expression below (where I get the start/end times from a date picker and two dropdown controls):

    DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.Selected.Value), Value(ddMinuteStart.Selected.Value), 0),
     dtEnd.SelectedDate + Time(Value(ddHourEnd.Selected.Value), Value(ddMinuteEnd.Selected.Value), 0),
     Hours) &
    ":" &
    Mod(
     DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.Selected.Value), Value(ddMinuteStart.Selected.Value), 0),
     dtEnd.SelectedDate + Time(Value(ddHourEnd.Selected.Value), Value(ddMinuteEnd.Selected.Value), 0),
     Minutes),
     60)

    The attached app shows this formula in action. To open it, save it locally, then go to https://create.powerapps.com, select Open, Browse, and find the file that you saved before.

    Hope this helps!

  • SoPatt Profile Picture
    Microsoft Employee on at

    The Mod function gives you the remainder after integer division.

     

    So I think an expression that gives you what you want would be:

    RoundDown(
     DateDiff(
     txtStartDate.SelectedDate, 
     txtEndDate.SelectedDate, 
     Minutes
     )/60
    ) & " hours and " & 
    Mod(
     DateDiff(
     txtStartDate.SelectedDate, 
     txtEndDate.SelectedDate, 
     Hours
     ),60
    ) & "minutes"

     

     

  • Community Power Platform Member Profile Picture
    on at

    Thank you very much, this was what I was looking for!

  • Community Power Platform Member Profile Picture
    on at

    Hi Carlos.

     

    This formula has been working for me until today. The first DateDiff has invalid arguments and the error reads "The DateDIff function has some invalid arguments." and the end of the first formula where Hours is, an error message reads "Invalid arguments type (Number). Expecting a Text value instead."

     

    The other DateDIff formula works fine but for some reason, Hours is not working. Minutes, Days and Years works fine.

     

    Any idea as to why this is? 

     

    Thanks!

  • Pierrot-56 Profile Picture
    18 on at

    Hello Carlos, it doesn't seem to be working.
    the difference between hours:minutes is not calculated when there are minutes; the formula adds an hour in my case; please let me know how to correct this.

    HoursMinutes).png

  • CarlosFigueira Profile Picture
    on at

    @Pierrot-56 what is the expression that you are currently using?

  • Pierrot-56 Profile Picture
    18 on at

    @CarlosFigueira Thanks for the reply
    The formula is that of the example that you were kind enough to provide


     

    DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.SelectedText.Value); Value(ddMinuteStart.SelectedText.Value); 0);
     dtEnd.SelectedDate + Time(Value(ddHourEnd.SelectedText.Value); Value(ddMinuteEnd.SelectedText.Value); 0);
     Hours) &
    ":" &
    Mod(
     DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.SelectedText.Value); Value(ddMinuteStart.SelectedText.Value); 0);
     dtEnd.SelectedDate + Time(Value(ddHourEnd.SelectedText.Value); Value(ddMinuteEnd.SelectedText.Value); 0);
     Minutes);
     60)​

     


    DateDiff.png

  • CarlosFigueira Profile Picture
    on at

    It seems like DateDiff for the hours is operating on the hours directly (9 to 13) or rounding it up, instead of the time difference (3:15). You can fix that by calculating the difference in minutes, and rounding down to the nearest 60, with the expression below:

    RoundDown(DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.SelectedText.Value); Value(ddMinuteStart.SelectedText.Value); 0);
     dtEnd.SelectedDate + Time(Value(ddHourEnd.SelectedText.Value); Value(ddMinuteEnd.SelectedText.Value); 0);
     Minutes) / 60; 0) &
    ":" &
    Mod(
     DateDiff(
     dtStart.SelectedDate + Time(Value(ddHourStart.SelectedText.Value); Value(ddMinuteStart.SelectedText.Value); 0);
     dtEnd.SelectedDate + Time(Value(ddHourEnd.SelectedText.Value); Value(ddMinuteEnd.SelectedText.Value); 0);
     Minutes);
     60)

    Another option to make this expression above a little more readable is to use the With function (which was introduced after I first replied to this post):

    With({
     startTime: dtStart.SelectedDate + Time(Value(ddHourStart.SelectedText.Value); Value(ddMinuteStart.SelectedText.Value); 0);
     endTime: dtEnd.SelectedDate + Time(Value(ddHourEnd.SelectedText.Value); Value(ddMinuteEnd.SelectedText.Value); 0)
     };
     With({
     diffMinutes: DateDiff(startTime; endTime; Minutes)
     };
     RoundDown(diffMinutes / 60; 0) & ":" & Mod(diffMinutes; 45)))

    Hope this helps!

  • Pierrot-56 Profile Picture
    18 on at

    Thanks for your time on this, it's working well now.

  • spollins Profile Picture
    2 on at

    Solution is not quite right in the first condition of the DateDiff if you are checking for hours this solution works well if the hours worked independent of minutes.  For example 2:15 to 4:00  would show 2hrs which is incorrect an if state on minutes needs to be added to hours logic if the end minutes are less than start subtract an hour

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard