cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
dmistry
Level 8

How to calculate time difference between two custom date picker controls along with time

Hi,

 

I researched enough before posting here and realized that there is no date picker control along with time built into POwerapp. So based on that I added a date picker control along with two drop downs: one for hours and one for mins. 

 

I am creating a repeating section control Overtime request app in POwerapps and need help on the same. 

I am working on below repeating section.

Capture.PNG

As you can see From is a (date picker), and Hour , Mins are drop downs where for hours I added (0,24) as each single choice, similarly 0-60 for mins. Now whatever user inputs here would be a Start Time.

Similarly I am going to have similar date picker and hours, mins drop downs for end time.

 

Now I need to calculate difference between end time and start time into decimal. So for example if entered Start time is : 5:00 AM to 6:40 PM then, I should get decimal difference of 1.7. If time frame is 5:00 am to 6:30 pm then difference would be 1.5.

 

Can someone please help me how to achive this, I have no idea how to make it work since.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to calculate time difference between two custom date picker controls along with time

Hi @dmistry ,

Do you want to calculate the hours difference between two date time values picked from DatePicker controls and Dropdown controls?

 

I have made a test on my side, please take a try with the following workaround:15.JPG

 

16.JPG

Add a Label control within your app, set the Text property to following:

RoundDown(DateDiff(
          FromDatePicker.SelectedDate+Time(Value(HourDropdown1.Selected.Value), Value(MinuteDropdown1.Selected.Value),0),
          ToDatePicker.SelectedDate+Time(Value(HourDropdown2.Selected.Value), Value(MinuteDropdown2.Selected.Value),0),
          Minutes
)/60, 0) +
Round(Mod(
    DateDiff(
          FromDatePicker.SelectedDate+Time(Value(HourDropdown1.Selected.Value), Value(MinuteDropdown1.Selected.Value),0),
          ToDatePicker.SelectedDate+Time(Value(HourDropdown2.Selected.Value), Value(MinuteDropdown2.Selected.Value),0),
          Minutes
   ),
   60
)/60,
1)

Note: The HourDropdown1 and MinuteDropdown1 are Dropdown boxes for From DatePicker. The HourDropdown2 and MinuteDropdown2 are Dropdown boxes for To DatePicker.

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Super User
Super User

Re: How to calculate time difference between two custom date picker controls along with time

I don't know the names of your fields but the formula would look something like below. Also I didn't understand the decimal calculation and how 5 AM - 6:30 PM was 1.5. The example below is providing the number of hours but you can change the calculation to whatever you need.

 

DateDiff(
    DateTimeValue(
        Concatenate(
            Text(DatePickerStart.SelectedDate),
            " ",
            ddStartHour.Selected.Value,
            ":",
            ddStartMin.Selected.Value,
            " ",
            ddStartAMPM.Selected.Value
        )
    ),
    DateTimeValue(
        Concatenate(
           Text(DatePickerEnd.SelectedDate),
            " ",
            ddEndHour.Selected.Value,
            ":",
            ddEndMin.Selected.Value,
            " ",
            ddEndAMPM.Selected.Value
        )
    ),
    Minutes
) / 60


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
dmistry
Level 8

Re: How to calculate time difference between two custom date picker controls along with time

Thanks @Jeff_Thorpe . From decimal calculation, I was referring to calculated column formula for Total Hours field below: =MOD(To-From,1)*24

Where To and From are datetime fields in sharepoint. See screenshot below.

Capture.PNG

Super User
Super User

Re: How to calculate time difference between two custom date picker controls along with time

If you are looking for total hours between start and end time then the formula I provided does just that. If you want to round it off to one decimal point then we can just add the Round().

 

Round(  
  DateDiff(
    DateTimeValue(
      Concatenate(
        Text(DatePickerStart.SelectedDate),
        " ",
        ddStartHour.Selected.Value,
        ":",
        ddStartMin.Selected.Value,
        " ",
        ddStartAMPM.Selected.Value
      )
    ),
    DateTimeValue(
      Concatenate(
         Text(DatePickerEnd.SelectedDate),
        " ",
        ddEndHour.Selected.Value,
        ":",
        ddEndMin.Selected.Value,
        " ",
        ddEndAMPM.Selected.Value
      )
    ),
    Minutes
  ) / 60,
  1
)


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Community Support Team
Community Support Team

Re: How to calculate time difference between two custom date picker controls along with time

Hi @dmistry ,

Do you want to calculate the hours difference between two date time values picked from DatePicker controls and Dropdown controls?

 

I have made a test on my side, please take a try with the following workaround:15.JPG

 

16.JPG

Add a Label control within your app, set the Text property to following:

RoundDown(DateDiff(
          FromDatePicker.SelectedDate+Time(Value(HourDropdown1.Selected.Value), Value(MinuteDropdown1.Selected.Value),0),
          ToDatePicker.SelectedDate+Time(Value(HourDropdown2.Selected.Value), Value(MinuteDropdown2.Selected.Value),0),
          Minutes
)/60, 0) +
Round(Mod(
    DateDiff(
          FromDatePicker.SelectedDate+Time(Value(HourDropdown1.Selected.Value), Value(MinuteDropdown1.Selected.Value),0),
          ToDatePicker.SelectedDate+Time(Value(HourDropdown2.Selected.Value), Value(MinuteDropdown2.Selected.Value),0),
          Minutes
   ),
   60
)/60,
1)

Note: The HourDropdown1 and MinuteDropdown1 are Dropdown boxes for From DatePicker. The HourDropdown2 and MinuteDropdown2 are Dropdown boxes for To DatePicker.

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 53 members 4,942 guests
Please welcome our newest community members: