cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## show the difference of DateDiff as Days, hours and minutes

Hi Comunnity!

I am dealing with something that I am sure must be simple but I've not been able to solve so far, I have two dates, declared as StartDate and EndDate. I need in other Label show the difference as Days, hours and minutes

Example:

I have a StartDate as 14/10/2020 6:00 and the EndDate as 18/10/2020 10:00 and I need in a different label show as:

4 days and 4 hours and 30 minutes

I have been reading several topics about it but still I am not able to solve it.

Can some of you guys give me a hand with this?

I really appreciate your usual help.

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps

[edited] Good point - apparently when calculating the difference between days the DateDiff function discards the time part - and when calculating the difference in hours it discards the minutes part. We can solve this by calculating the number of days using the hours - and dividing the result by 24 (rounding down), and a similar for the number of hours. This should work for your scenario:

With(
{
days: RoundDown(DateDiff(startDate; endDate; Hours) / 24; 0);
hours: Mod(RoundDown(DateDiff(startDate; endDate; Minutes) / 60; 0); 24);
minutes: Mod(DateDiff(startDate; endDate; Minutes); 60)
};
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

Hopefully it will work this time 🙂

5 REPLIES 5
Power Apps

You can use an expression like the one below to get what you need:

With(
{
days: DateDiff(startDate; endDate; Days);
hours: Mod(DateDiff(startDate; endDate; Hours); 24);
minutes: Mod(DateDiff(startDate; endDate; Minutes); 60)
};
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

The DateDiff function will give you a whole number of <units> that make up the difference between the two dates; since you already have the days, you only need to use the remainder of the number of hours divided by 24 (using the Mod function). Similarly to the number of minutes.

The attached app shows this expression for your scenario. To open it, save it locally, then go to https://create.powerapps.com, select Open -> Browse, and find the file that you saved.

Hope this helps!

Anonymous
Not applicable

@CarlosFigueira

Thank for your answer, I have check it with your atteched example and its works but I am frustrated as when the hour of the EndDate is lower than the Hour of the StarDate it do not calculate as supposed to be, I have made this screenshoot to explain it better.

Do you have any idea how to fix it?

Thank you!!

Power Apps

[edited] Good point - apparently when calculating the difference between days the DateDiff function discards the time part - and when calculating the difference in hours it discards the minutes part. We can solve this by calculating the number of days using the hours - and dividing the result by 24 (rounding down), and a similar for the number of hours. This should work for your scenario:

With(
{
days: RoundDown(DateDiff(startDate; endDate; Hours) / 24; 0);
hours: Mod(RoundDown(DateDiff(startDate; endDate; Minutes) / 60; 0); 24);
minutes: Mod(DateDiff(startDate; endDate; Minutes); 60)
};
days & " day(s), " & hours & " hour(s) and " & minutes & " minute(s)"
)

Hopefully it will work this time 🙂

Anonymous
Not applicable

@CarlosFigueira

Youre amazing! it works now.

Thank you!!

Regular Visitor

You're super, it worked for me, I hadn't been able to solve it for days.

Thank you!

Announcements

#### April 4th Copilot Studio Coffee Chat | Recording Now Available

Did you miss the Copilot Studio Coffee Chat on April 4th? This exciting and informative session with Dewain Robinson and Gary Pretty is now available to watch in our Community Galleries!   This AMA discussed how Copilot Studio is using the conversational AI-powered technology to aid and assist in the building of chatbots. Dewain is a Principal Program Manager with Copilot Studio. Gary is a Principal Program Manager with Copilot Studio and Conversational AI. Both of them had great insights to share with the community and answered some very interesting questions!     As part of our ongoing Coffee Chat AMA series, this engaging session gives the Community the unique opportunity to learn more about the latest Power Platform Copilot plans, where we’ll focus, and gain insight into upcoming features. We’re looking forward to hearing from the community at the next AMA, so hang on to your questions!   Watch the recording in the Gallery today: April 4th Copilot Studio Coffee Chat AMA