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

Displaying DateDiff from Hours and Minutes

Hello community,

 

I have an overtime calculation app which has Date + Time columns but I have removed the date and just left the Time with the default Hour + Minute controls in the Data Card.

 

Start and End of the overtime should be only hours and minutes , but I am having trouble validating the minutes and something is slipping my mind.

 

On another field I have the following :

 

DateDiff(Time(
Value(HourValue2.Selected.Value),
Value(MinuteValue2.Selected.Value),
0),Time(
Value(HourValue1.Selected.Value),
Value(MinuteValue1.Selected.Value),
0),Hours) & " " & "Hours" & " " & DateDiff(Time(
0,
Value(MinuteValue2.Selected.Value),
0),Time(
0,
Value(MinuteValue1.Selected.Value),
0),Minutes) & " " & "Minutes"

 

Which should display as X hours and Y minutes. The hour value is ok since you wont start an overtime before you end it so the calculation is fine. The minutes is what I m having issues with.

 

When the Start of the overt time is 13:30 and the End of the over time is 20:10 - it calculates it as 7 hours -20 minutes .

 

How could I validate the minutes so it calculates it without a negative value if the start minutes are more than the end minutes?

 

Thank you !

3 ACCEPTED SOLUTIONS

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @StanP ,

This may work better

With(
   {
      wTime: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      )
   },
   RoundDown(
      wTime / 60,
      0
   ) & " Hours," & 
   Mod(
      wTime,
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Hi @StanP ,

Something like this

With(
   {
      wTime1: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      ),
      wTime2: 
      DateDiff(
         Time(
            Value(HourValue3.Selected.Value),
            Value(MinuteValue3.Selected.Value),
            0
         ),
         Time(
            Value(HourValue4.Selected.Value),
            Value(MinuteValue4.Selected.Value),
            0
         ),
         Minutes
      )
   },
   RoundDown(
      (wTime + wTime2) / 60,
      0
   ) & " Hours," & 
   Mod(
      (wTime + wTime2),
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

@StanP ,

Probably something like this - note free-typed, so watch commas/brackets etc

With(
   {
      wTime1: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      ),
      wTime2: 
      RoundDown(
         Value(HourValue3.Selected.Value),
         0
      ) * 60 + 
      Value(MinuteValue3.Selected.Value)
   },
   RoundDown(
      (wTime + wTime2) / 60,
      0
   ) & " Hours," & 
   Mod(
      (wTime + wTime2),
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @StanP ,

This may work better

With(
   {
      wTime: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      )
   },
   RoundDown(
      wTime / 60,
      0
   ) & " Hours," & 
   Mod(
      wTime,
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Thank you @WarrenBelz ,

 

Just one last question , what if I wanted to add the hours/minutes from another set of dropdown menus (hours and minutes) to the formulate , so I can get an additional calculation in a separate field to the one above.

 

So to calculate the end of overtime - start of overtime like you showed me and I want to add another time value of hours and minutes from an hour and minute dropdowns:

 

(The outcome of the formula that you posted) + hours and minutes from another hour hour/minute dropdown = in another field.

 

Thank you!

Hi @StanP ,

Something like this

With(
   {
      wTime1: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      ),
      wTime2: 
      DateDiff(
         Time(
            Value(HourValue3.Selected.Value),
            Value(MinuteValue3.Selected.Value),
            0
         ),
         Time(
            Value(HourValue4.Selected.Value),
            Value(MinuteValue4.Selected.Value),
            0
         ),
         Minutes
      )
   },
   RoundDown(
      (wTime + wTime2) / 60,
      0
   ) & " Hours," & 
   Mod(
      (wTime + wTime2),
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Thanks @WarrenBelz ,

 

I didn't explain my last question properly , apologies for that.

 

What I meant was - lets say I have 3 dropdowns - the 2 date time fields in your first response where I have to calculate the difference in the times - and I have another set of dropdowns (hours and minutes) which I have to add to the already calculated difference from timevalue1 and timevalue2 . It would be DateDiff(Timevalue1,TimeValue2) + TimeValue3(the dropdowns with hour and minutes added to the DateDiff) in another field difference from where we calculated the DateDiff

 

Thank you!

 

 

@StanP ,

Probably something like this - note free-typed, so watch commas/brackets etc

With(
   {
      wTime1: 
      DateDiff(
         Time(
            Value(HourValue1.Selected.Value),
            Value(MinuteValue1.Selected.Value),
            0
         ),
         Time(
            Value(HourValue2.Selected.Value),
            Value(MinuteValue2.Selected.Value),
            0
         ),
         Minutes
      ),
      wTime2: 
      RoundDown(
         Value(HourValue3.Selected.Value),
         0
      ) * 60 + 
      Value(MinuteValue3.Selected.Value)
   },
   RoundDown(
      (wTime + wTime2) / 60,
      0
   ) & " Hours," & 
   Mod(
      (wTime + wTime2),
      60
   ) & "Minutes"
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

Brilliant @WarrenBelz !

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,015)