Data

Displaying Days, Hours and Minutes between two Date/Time values

Have you ever wanted to see exactly how many hours, minutes and seconds are between two selected date/time values. The formula below assumes that the user has selected from two Date Pickers with the Hour and Minute value from drop-down controls (as are provided by a standard Power Apps Date and Time field controls).

With(
   {
      _Calc: DateDiff(
         StartDatePicker.SelectedDate + Time(
            Value(StartHourDD.Selected.Value),
            Value(StartMinuteDD.Selected.Value),
            0
         ),
         EndDatePicker.SelectedDate + Time(
            Value(EndHourDD.Selected.Value),
            Value(EndMinuteDD.Selected.Value),
            0
         ),
         TimeUnit.Minutes
      )
   },
   With(
      {
         _Days: RoundDown(
            _Calc / 1440,
            0
         ),
         _DayMins: Mod(
            _Calc,
            1440
         )
      },
      With(
         {
            _Hours: RoundDown(
               _DayMins / 60,
               0
            ),
            _Minutes: Mod(
               _DayMins,
               60
            )
         },
         _Days & " Days  " & _Hours & " Hours  " & _Minutes & " Minutes"
      )
   )
)

To explain briefly the logic

  • _Calc is the total number of minutes between the two date/time values.
  • _Days is the whole days from _Calc
  • _DayMins is the total minutes remaining after subtracting the minutes in _Days
  • _Hours is then the whole hours from _DayMins
  • _Minutes is the remaining minutes after subtracting the minutes in _Hours.
  • The message at the bottom (if a Label is used) displays it all.

Leave a Reply

Your email address will not be published. Required fields are marked *