calculate the difference between two dates times in infopath form 2010


  • 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

    Dienstag, 28. Februar 2012 14:29


Alle Antworten

  • 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.

    Dienstag, 28. Februar 2012 15:20
  • 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)

    Dienstag, 28. Februar 2012 15:47
  • XPath should like like this:DateTime2 - Datetime1

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

    Dienstag, 28. Februar 2012 16:11
  • Dienstag, 28. Februar 2012 16:20
  • 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.

    • Als Antwort vorgeschlagen Ali_ARK Mittwoch, 25. April 2012 19:05
    • Nicht als Antwort vorgeschlagen Ali_ARK Mittwoch, 25. April 2012 19:05
    • Als Antwort vorgeschlagen Prasad305 Donnerstag, 21. August 2014 08:59
    • Nicht als Antwort vorgeschlagen Prasad305 Donnerstag, 21. August 2014 08:59
    Mittwoch, 25. April 2012 17:02
  • 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).

    • Bearbeitet Ali_ARK Mittwoch, 25. April 2012 19:10
    Mittwoch, 25. April 2012 19:07