cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Super User III
Super User III

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

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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (48,169)