How to calculate the duration of two date and time fields

  • caseySOFU
    Asked on May 17, 2022 at 2:17 PM

    Hi! If we capture a start date and time and an end date and time, is there a way for the system to calculate the duration?


    Thank you


    Casey

  • Rose JotForm Support
    Replied on May 17, 2022 at 4:34 PM

    Hi Casey,

    I am currently working on your concern and need more time. I will get back to you shortly. Thank you.


  • Rose JotForm Support
    Replied on May 17, 2022 at 5:41 PM

    Hi Casey,

    To calculate the Date and Time duration, you need to add multiple Form Calculation widgets to your form. Then, add the following formula in each corresponding widget:

    1652823225 628414b9b13d0  Screenshot 10

    To get the raw difference between the 2 date and time fields:

    1652823124 628414540e8ad  Screenshot 21

    To get the days difference:

    1652823171 6284148331f15  Screenshot 32

    To get the raw hours and minutes difference:

    1652823199 6284149f6fbc2  Screenshot 43

    To get the hours difference:

    1652823255 628414d7d7101  Screenshot 54

    To get the minutes difference:

    1652823281 628414f160644  Screenshot 65

    Then, to summarize the total duration difference, you can add a Pharagraph element and add the unique name of the days, hours, and minutes field.

    1652823439 6284158f4ec76  Screenshot 76

    I also suggest that you hide the calculation widgets from the form view:

    1652823511 628415d771567  Screenshot 87

    Here's the output:

    1652823654 628416661dd0c  Screenshot 98

    Here's the clone form https://form.jotform.com/221366853182963, you may view it for demo purposes or you can also clone it.

    Please give it a try and let us know if you need any help.