How to perform subtract operation on textbox with time data type in Infopath forms 2007? - InfoPath Dev
in

InfoPath Dev

How to perform subtract operation on textbox with time data type in Infopath forms 2007?

Last post 11-07-2013 10:01 AM by missieyohko. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 03-01-2011 06:11 AM

    How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Hi Folks, I am having 2 text box - Time1 & Time2 with time data type (HH:MM 24hrs format). I need to do subtract operation between Time2 and Time1. Example: Time2:19:30 & Time1:19:00. So, Time2 - Time1. Result: 00:30. Please guide. Thanks. Chintan
    Thanks,
    Chintan
  • 03-02-2011 03:28 AM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Hi Chintan,

    You can do this via custom code, or use the DateDiff command in qRules. The documentation included in the trial contains an example of DateDiff!

    Good luck.

    Ernesto Machado
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™


  • 03-02-2011 03:31 AM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Hi Chintan,

    qRules does this via the DateDiff command, and in fact there is an example in the documentation included in the trial.

    The other option is to write custom code.

    Good luck!

    Ernesto Machado
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™


  • 03-02-2011 08:11 AM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    This can be done using a complicated default value formula:

    concat(substring(100 + number(concat("0", substring(../my:Time2, 1, 2))) - number(concat("0", substring(../my:Time1, 1, 2))), 2, 2), ":", substring(100 + number(concat("0", substring(../my:Time2, 4, 2))) - number(concat("0", substring(../my:Time1, 4, 2))), 2, 2), ":", substring(100 + number(concat("0", substring(../my:Time2, 7, 2))) - number(concat("0", substring(../my:Time1, 7, 2))), 2, 2))

    This assumes that Time2 is always intended to be greater than Time1. It will work if both Time1 and Time2 are blank, or if only Time2 is blank.

  • 03-03-2011 11:27 PM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Thx Greg, Your given code was very useful. It satisfy my requirement.
    Thanks,
    Chintan
  • 04-19-2011 03:45 PM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

     Glad to help

  • 04-20-2011 06:27 AM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    I have the same situation, just that I am trying to verify the time against an entry field. Here is what I have:

    Total hrs (10.0)

    Start (7:00)

    End (17:00)

    What I would like to do is make sure that when the user goes to enter the end time, that if verfies that (End - Start) = Total hrs. This way they will be notified after entry that they need to enter the correct time.

  • 04-20-2011 01:51 PM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Hi there,

    If you have IP2007 + you can use the built in addSeconds(time, secondsToAdd) function. 10 hrs * 60 min * 60 sec = 36000 seconds, so the condition is If endTime Is Not Equal To addSeconds(startTime, 36000).

    If you have IP2003, you can hook up something similar with the formula above ^.

    Hope this helps!
  • 11-07-2013 10:01 AM In reply to

    Re: How to perform subtract operation on textbox with time data type in Infopath forms 2007?

    Greg Collins:

    This can be done using a complicated default value formula:

    concat(substring(100 + number(concat("0", substring(../my:Time2, 1, 2))) - number(concat("0", substring(../my:Time1, 1, 2))), 2, 2), ":", substring(100 + number(concat("0", substring(../my:Time2, 4, 2))) - number(concat("0", substring(../my:Time1, 4, 2))), 2, 2), ":", substring(100 + number(concat("0", substring(../my:Time2, 7, 2))) - number(concat("0", substring(../my:Time1, 7, 2))), 2, 2))

    This assumes that Time2 is always intended to be greater than Time1. It will work if both Time1 and Time2 are blank, or if only Time2 is blank.

    I'm sorry to revive a dead thread but I'm curious about some of this logic...  When I want to understand long equations I write them out step by step... So I hope this makes sense and if I've made an error please let me know where...

    STARTTIME 12:00:00
    ENDTIME   13:00:00

    substring(100 + number(concat("0", substring(../my:EndTime, 1, 2))) - number(concat("0", substring(../my:StartTime, 1, 2))), 2, 2)
    substring(100 + number(concat("0", "03"                          )) - number(concat("0", "02"                            )), 2, 2)
    substring(100 + number("003"                                      ) - number("002"                                       )), 2, 2)
    substring(100 + 3                                                   - 2                                                   ), 2, 2)
    substring(101                                                                                                             ), 2, 2)
    "01"

    What was the point of concatenating "0" in the 3rd step?

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.