# Calculating Time Difference in InfoPath Form

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

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

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/

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
``````

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.
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"), "-", "")))`