How to get the difference between two Time Fields?

  • deweese
    Asked on June 29, 2017 at 5: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.

  • Support_Management Jotform Support
    Replied on June 29, 2017 at 7: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:

    How to get the difference between two Time Fields? Image 1 Screenshot 40

    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:

    How to get the difference between two Time Fields? Image 2 Screenshot 51

    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:

    How to get the difference between two Time Fields? Image 3 Screenshot 62

  • deweese
    Replied on June 30, 2017 at 8:13 AM

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