How to calculate the time difference?

  • Profile Image
    zehrabatool
    Asked on June 06, 2017 at 01:20 AM

    i want to calculate the time in the following field, how can i achieve this?

     

  • Profile Image
    Nik_C
    Answered on June 06, 2017 at 03:58 AM

    Maybe you could enable time range for one time field:

    And then you could add Text field that could show the range:

    And it would look like this:

    Could that work for you?

    Please let us know.

    Thank you!

  • Profile Image
    zehrabatool
    Answered on June 06, 2017 at 04:43 AM
    No it won’t be working for me.
    As I won’t hours and minutes separately in text field.
    As I have shown you in a figure below.
    I don’t want it to be done by using date picker field. How can I obtained it by using only time field?
    Regards
    zehra
    ...
  • Profile Image
    zehrabatool
    Answered on June 06, 2017 at 04:43 AM
    No it won’t be working for me.
    As I want hours and minutes separately in text field.
    As I have shown you in a figure below.
    I don’t want it to be done by using date picker field. How can I obtained it by using only time field?
    Regards
    zehra
    ...
  • Profile Image
    Nik_C
    Answered on June 06, 2017 at 05:38 AM

    I understand. 

    I was able to make a logic that will calculate hours and minutes between two fields and place them in separate fields. 

    It's a bit complicated but it is doing what you need.

    1) Change the time field to 24h time format:

    And do that for both time fields.

    2) The issues we have in this calculation is that we need the time and hours separated, but also we need those two correct if the value is negative, for example out time is 15:10 and in time is 10:50, if we just subtract them we will get 5h and -40 minutes, so we need some additional fields:

    And Minutes total is Form calculations widget.

    They could be all hidden except Hours final and minutes final since there we will show the final hours and minutes difference.

    3) Now we create some conditions:

    -First the hours:

    Since it will be the decimal number we use the round function and that will give us hours number

    -Second, we create a condition for minutes:

    -To extract the actual minutes, we use the Form Calculations widget we added to the form:

    We subtract the minutes and hours to get the decimal part, multiply that number with 3600 to get seconds and divide with 60 to get the minutes. Finally we round that number to get the actual minutes value.

    4) To cover the negative numbers I mentioned above, we add four more conditions:

    -For negative:

    So if the minutes is less than zero, we subtract number one from the hours and enter in hours final field (that's our total hours) and similarly for minutes we add 60 to value so we get the number of minutes.

    -For positive:

    We just copy the values to hours total and minutes total.

    Here is my test form so you can check it out: https://form.jotformpro.com/71561743287967

    Again, the temp value fields should be hidden:

    Please let us know your thoughts.

    Thank you!

  • Profile Image
    zehrabatool
    Answered on June 06, 2017 at 06:43 AM
    Why it’s not showing in Final hours ?
    ...
  • Profile Image
    liyam
    Answered on June 06, 2017 at 08:39 AM

    Hello,

    I just tested the form provided by Nik_C and the field appear to be properly filled after filling up time 1 and time 2:

    Can you try refreshing the form page to see if the problem appears still?

    Thanks.

  • Profile Image
    zehrabatool
    Answered on June 07, 2017 at 12:43 AM
    Please kindly see this screenshot, when I am selecting time 1: 1:00 and time 2: 2:00.
    It’s not showing in final hours and final minutes.
    Link is as following:
    https://form.jotformpro.com/71561743287967
    Do you please help me as soon as possible?
    ...
  • Profile Image
    Nik_C
    Answered on June 07, 2017 at 02:15 AM

    My apologies, that is happening because I didn't cover that situation. But that is easily done by adding two more conditions:

    But if you don't want zero to show for minutes, you can include only first condition.

    And here is my updated form: https://form.jotformpro.com/71561743287967

    Let us know how it worked for you.

    Thank you!

  • Profile Image
    Chriistian
    Answered on June 21, 2017 at 10:49 PM

    @SafetyJNJMech,

    Thanks for your update. Yes, you are correct, the Minutes Total field is a Form calculation widget so you can add an extra calculation to it to get the break time deduction.

    We appreciate your kind words. If you have questions or concerns, please open a separate thread and we will be happy to assist you.

    Regards.