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
Pstork1
Dual Super User III
Dual Super User III

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.

View solution in original post

6 REPLIES 6
Pstork1
Dual Super User III
Dual Super User III

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.

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!

Pstork1
Dual Super User III
Dual Super User III

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.

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?

Pstork1
Dual Super User III
Dual Super User III

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.

View solution in original post

Brilliant, thanks for your support @Pstork1 !

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,499)