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

Re: DateDiff calculation not using AMPM

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

Re: DateDiff calculation not using AMPM

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

Highlighted
Helper I
Helper I

Re: DateDiff calculation not using AMPM

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

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,350)