cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

DateDiff calculation not using AMPM

Help!  New to powerapps and just can't find the answer.  I have a calculation for the minutes between start time field and end time field.  The calculation works until the calculation crosses between am to pm.  Below is my code.  What am I doing wrong ?

 

DateDiff(
DateValue2.SelectedDate + Time(Value(HourValue2.Selected.Value), Value(MinuteValue2.Selected.Value), Value(AmPmValue2.Selected.Value), 0),
DateValue3.SelectedDate + Time(Value(HourValue3.Selected.Value), Value(MinuteValue3.Selected.Value), Value(AmPmValue3.Selected.Value), 0),
Minutes)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @Anonymous ,

I have never used the am/pm and I can't find any reference to it working, however there is one error needing correction for it to have any chance - the am/pm is text, so you do not need Value in front of it.

DateDiff(
   DateValue2.SelectedDate + 
   Time(
      Value(HourValue2.Selected.Value), 
      Value(MinuteValue2.Selected.Value), 
      AmPmValue2.Selected.Value, 0
   ),
   DateValue3.SelectedDate + 
   Time(
      Value(HourValue3.Selected.Value), 
      Value(MinuteValue3.Selected.Value), 
      AmPmValue3.Selected.Value, 0),
   Minutes
)

If this does not work, try

DateDiff(
   DateValue2.SelectedDate + 
   Time(
      If(
         AmPmValue2.Selected.Value = "PM",
         Value(HourValue2.Selected.Value) + 12,
         Value(HourValue2.Selected.Value)
      ),
      Value(MinuteValue2.Selected.Value), 0
   )
   ,
   DateValue3.SelectedDate + 
   Time(
      If(
         AmPmValue3.Selected.Value = "PM",
         Value(HourValue2.Selected.Value) + 12,
         Value(HourValue3.Selected.Value)
      ),
      Value(MinuteValue3.Selected.Value), 0
   ),
   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

2 REPLIES 2
WarrenBelz
Super User
Super User

Hi @Anonymous ,

I have never used the am/pm and I can't find any reference to it working, however there is one error needing correction for it to have any chance - the am/pm is text, so you do not need Value in front of it.

DateDiff(
   DateValue2.SelectedDate + 
   Time(
      Value(HourValue2.Selected.Value), 
      Value(MinuteValue2.Selected.Value), 
      AmPmValue2.Selected.Value, 0
   ),
   DateValue3.SelectedDate + 
   Time(
      Value(HourValue3.Selected.Value), 
      Value(MinuteValue3.Selected.Value), 
      AmPmValue3.Selected.Value, 0),
   Minutes
)

If this does not work, try

DateDiff(
   DateValue2.SelectedDate + 
   Time(
      If(
         AmPmValue2.Selected.Value = "PM",
         Value(HourValue2.Selected.Value) + 12,
         Value(HourValue2.Selected.Value)
      ),
      Value(MinuteValue2.Selected.Value), 0
   )
   ,
   DateValue3.SelectedDate + 
   Time(
      If(
         AmPmValue3.Selected.Value = "PM",
         Value(HourValue2.Selected.Value) + 12,
         Value(HourValue3.Selected.Value)
      ),
      Value(MinuteValue3.Selected.Value), 0
   ),
   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.

Anonymous
Not applicable

The second code is working like a charm.  Thank you!

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Users online (2,616)