cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndyH_JSY
Helper II
Helper II

DateDiff calculating mm/dd/hh/mm

Hello!

 

I've been trawling the forums trying to find a solution to this problem, but it seems a bit more complex than first envisioned. 

 

I have a start date, formatted: "yyyy-dd-mm hh:mm:ss", I simply want to display a counter on the screen, showing the below (since the opened date).

 

- Months

- Days

- Hours 

- Mins

E.G: "1 day, 12 hours, 43 minutes since the opened date"

 

Does anyone have any example code or advise they could share please? 

 

Thanks in advanced!

1 ACCEPTED SOLUTION

Accepted Solutions

I just noticed an error in my code where its still using 

DatePicker1.SelectedDate

Make sure that all those entries get switched to 'myDate'.  if your date is correct then it should work.  It does in my test.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User
Dual Super User

The key here is that you need to do each calculation recursively based on the previous calculation.

So to get Days it would be

DateDiff(StartDate,Now(),Days)

To get hours its the same calculation in Hours - the days * 24 

With({DaysDiff:DateDiff(DatePicker1.SelectedDate,Now(),Days)* 24},Text(DateDiff(DatePicker1.SelectedDate,Now(),Hours)-DaysDiff,"[$-en-US]##0"))

  And the minutes remaining uses the same pattern

With({MinutesDiff:DateDiff(DatePicker1.SelectedDate,Now(),Hours)* 60},Text(DateDiff(DatePicker1.SelectedDate,Now(),Minutes)-MinutesDiff,"[$-en-US]##0"))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Thanks for your reply, I tried this but it dosen't seem to give me the right result:

 

DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Days) &
With({DaysDiff:DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Days)* 24},Text(DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time), Now(), Hours)-DaysDiff,"[$-en-US]##0")) &
With({MinutesDiff:DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time),Now(),Hours)* 60},Text(DateDiff(DateTimeValue(DataTable1.Selected.u_failure_time),Now(),Minutes)-MinutesDiff,"[$-en-US]##0"))

 

DataTable1.Selected.u_failure_time = 2021-02-04 21:16:00

 

The result of this should be approx 32 days, 20 hours, 47 mins. The result on PowerApps is 33days, 3 hours and 13 mins. 

 

Any further suggestions are welcomed!

If you want to concatenate the whole thing I would use Concatentate() and seperate each entry by commas rather than &.  Like this:

With(
    {myDate: DateTimeValue(DataTable1.Selected.u_failure_time)},
    Concatenate(
        Text(
            DateDiff(
                myDate,
                Now(),
                Days
            )
        ),
        " days, ",
        With(
            {
                DaysDiff: DateDiff(
                    myDate,
                    Now(),
                    Days
                ) * 24
            },
            Text(
                DateDiff(
                    myDate,
                    Now(),
                    Hours
                ) - DaysDiff,
                "[$-en-US]##0"
            )
        ),
        " hours, ",
        With(
            {
                MinutesDiff: DateDiff(
                    myDate,
                    Now(),
                    Hours
                ) * 60
            },
            Text(
                DateDiff(
                    DatePicker1.SelectedDate,
                    Now(),
                    Minutes
                ) - MinutesDiff,
                "[$-en-US]##0"
            )
        ),
        " seconds"
    )
)


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Thank you!

 

That calculates the days correct, but its still an issue with the hours and mins. The hours show -3 and the mins show 8, it should be approx 20hrs and 47mins.

 

Perhaps this is an issue with my date/time input's format?

I just noticed an error in my code where its still using 

DatePicker1.SelectedDate

Make sure that all those entries get switched to 'myDate'.  if your date is correct then it should work.  It does in my test.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Join me at 365 and PWR EduCon in Chicago
EduCon Chicago 2022

Brilliant, thanks for your support @Pstork1 !

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,917)