cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Leapster
Helper I
Helper I

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 @Leapster ,

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 @Leapster ,

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

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

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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