1

Is there any way to calculate the difference between two time fields in an InfoPath 2013 form in minutes? Time Arrived: 1:00PM Time Left: 2:00PM Difference: 60

I understand that this can be done in the SP list using calculated fields, but the user wants the time difference to be seen on the InfoPath form once the time arrived and left have been entered. Thank you in advance for your help.

  • don't please find a workarround for this, date time calculations are horrible in infopath – Mike May 31 '18 at 20:03
2

The same question asked years ago

Calculate time differences in InfoPath

In this link, you can able to see one more that helps you to design calculating-time-differences-in-infopath-without-custom-code

If you need with custom code then it will help you to overcome with custom code For more Reference

1

I believe this will help you sort your issue.

http://www.meartechnology.co.uk/blog/2016/09/16/infopath-calculate-business-days-between-2-dates-including-leap-year/

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

0

Yes it can be done using Infopath.You can use below expression which actually check the time difference

(number(substring(../my:endTime, 1, 2)) * 3600 + number(substring(../my:endTime, 4, 2)) * 60 – (number(substring(., 1, 2)) * 3600 + number(substring(., 4, 2)) * 60)) div 3600 >= 0

Please look into following sites which have implemented it using this expression

http://www.bizsupportonline.net/infopath2003/time-calculations-infopath-using-rules.htm

http://www.formsonfire.com/infopath/calculating-time-differences-in-infopath-without-custom-code/

0

Almost the same as the previously proposed solution, but instead of just checking for >=0 (true/false), this actually returns the value in minutes.

To calculate minutes,

((number(substring(StopTime, 1, 2)) * 3600 + number(substring(StopTime, 4, 2)) * 60 - (number(substring(StartTime, 1, 2)) * 3600 + number(substring(StartTime, 4, 2)) * 60)) / 3600) * 60

Set the InfoPath field that will display the result to decimal if your want hours to display the fractions.

To calculate hours,

(number(substring(StopTime, 1, 2)) * 3600 + number(substring(StopTime, 4, 2)) * 60 - (number(substring(StartTime, 1, 2)) * 3600 + number(substring(StartTime, 4, 2)) * 60)) / 3600
0

I utilize a separate SharePoint list to help calculate the number of days between two dates in Infopath. This is so I can account for leap years and have the ability to just count work days, not all days. I update this list with new data once a year.

Here is the Excel file source for the list containing 2018-2020 data: https://1drv.ms/x/s!ApLhBloaS1wVgsUOMRrRfbekFftY9Q

Steps:

  1. Import the first worksheet of the above Excel file as a new list in Sharepoint.
  2. Add a receive data connection to this list from your InfoPath form.
  3. For the first date, create a action to convert the date to a number in YYYYMMDD format. Assuming the date is stored as DateTime, you can use this formula: floor(number(translate(substring-before(../my:endDate, "T"), "-", "")))
  4. Query the list for the number value of the first date. Store this number in a field (column) in your form. (This field does not need to show in your form.)
  5. Repeat steps 3 & 4for the second date.
  6. Subtract the first date number from the 2nd, store this in a third column.

Note: The Excel file uses the formula "NETWORKDAYS" and includes columns for weekdays, weekdays minus US Federal holidays, and weekdays minus NYSE holidays. Now you can get the number of work days between two dates using one of these columns. If you live outside the US, you could add a column to the Excel for other holidays, such as UK bank holidays.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.