What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How to get the difference between two Time Fields then break it down into Hours and Minutes?

    Asked by deweese on June 29, 2017 at 05:49 PM

    How can you get the decimal correct for result from two times? For example, total hours/mins from a start and end time.



    This is a re-post of a comment on How to Perform Form Calculation Using a Widget

  • Profile Image
    JotForm Support

    Answered by Jim_R on June 29, 2017 at 07:29 PM

    I guess what you're asking is how to extract the decimal places of a calculated result. Perhaps you're getting the difference between 2 Time Fields, and you wanted to show the number of hours and minutes.

    Is this the form you're working on 71793741584164?

    Here's a cloned copy of it showing how it's done 71797818078979

    Follow these steps to achieve this:

    1. Add 2 Form Calculation Widgets below Start Time and End Time, then label them as Hours and Minutes.

    2. Set the HOURS formula as shown below:

    The floor() function rounds down a number. So regardless of the decimal place, the only value that will be calculated on the HOURS field is the rounded down whole number.

    3. Then, the MINUTES formula like so:

    This time, the formula looks a bit complicated but it's really straight forward. The round() function was used to round off (not round down) the result.

    Basically, you would need to get the decimal places of the difference first. You can get that by subtracting the floored difference from the normal difference.

    e.g.

    5.67 - 5 = 0.67

    Then, to get the MINUTES equivalent, just multiply it by 60.

    Result:

  • Profile Image

    Answered by deweese on June 30, 2017 at 08:13 AM

    Ahh, thanks so much.  That makes sense!  That worked like a charm.