calculate the difference between two dates times in infopath form 2010 RRS feed

  • Question

  • Hi,

    I have an infopath 2010 form that contains three fields:
    2 date time and the 3rd contains the difference between the two in hours
    how I can make the difference between the two so that the display will be like this:
    Date Time1           05/01/2010           22:00 
    Date Time2           6/1/2010                  1:00
    Diff Field                                               3:00
    thank you in advance for your answer

    Tuesday, February 28, 2012 2:29 PM


All replies

  • You should include that information in the Date/Time picker fields so that infopath knows how to calculate the Date/Time. Avoid using Plain text.

    Then create calculated value field for the Difference. XPath should like like this: DateTime2 - Datetime1

    ..then Disable the date/time pickers if you dont this this info to be edited/changed.

    Tuesday, February 28, 2012 3:20 PM
  • thanks for your reply

    but I've given you a simple example to display what I want to do.

    these fields must be completed by the user

    I can't do it with XPath

    I am forced to use the rules and code infopath like concat and substring etc. ...(formula infopath)

    Tuesday, February 28, 2012 3:47 PM
  • XPath should like like this:DateTime2 - Datetime1

    It would better if you'd test everything you recommend here as a solution before posting.


    Tuesday, February 28, 2012 4:11 PM
    • Marked as answer by Entan Ming Tuesday, March 6, 2012 7:29 AM
    Tuesday, February 28, 2012 4:20 PM
  • What if only wanted to get the difference between 2 Date/Time fields w/o the extra drop down to change the start time?

    I need to be able to have end users select the date & time of the start of an event and the end of an event. Then want the calc field to determine the difference down to the minute between the date/time (which could be weeks apart or just a few minutes apart...).

    Looking at the fx value of the form you (Alec) provided - I am unclear how to adjust the formula to do that.

    • Proposed as answer by Ali_ARK Wednesday, April 25, 2012 7:05 PM
    • Unproposed as answer by Ali_ARK Wednesday, April 25, 2012 7:05 PM
    • Proposed as answer by Prasad305 Thursday, August 21, 2014 8:59 AM
    • Unproposed as answer by Prasad305 Thursday, August 21, 2014 8:59 AM
    Wednesday, April 25, 2012 5:02 PM
  • I actually just found a different way to go about it. As I dont need the calculated value to display on the form, only as a column to be exported to excel, I added the calc field in Sharepoint instead of infopath :)

    *Also, this works out better since as I understand it - InfoPath limits you to 16 calc fields. Sharepoint seems to allow many more as I currently have 30-35 calc fields in one of my Sharepoint lists.

    **And Sharepoint calc fields I think are much easier to work with then using InfoPath calculations (whether if be a calc value object, a rule that is ran to display a calc, or field with a fx value calc added).

    • Edited by Ali_ARK Wednesday, April 25, 2012 7:10 PM
    Wednesday, April 25, 2012 7:07 PM