cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Displaying date difference in both hours and minutes

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Displaying date difference in both hours and minutes

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!

View solution in original post

4 REPLIES 4
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Displaying date difference in both hours and minutes

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!

View solution in original post

sopatte
Level 8

Re: Displaying date difference in both hours and minutes

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"

 

 

Anonymous
Not applicable

Re: Displaying date difference in both hours and minutes

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

Anonymous
Not applicable

Re: Displaying date difference in both hours and minutes

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!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,747)