Skip to main content
All CollectionsExamples & Tutorials
Calculate the difference between two date/time fields
Calculate the difference between two date/time fields

Let's explore how you can use calculated field to display the number of hours between two date/time fields.

Updated over 9 months ago

Using calculated values and with the assistance of the moment.js library you can easily display the difference between two date/time fields within Team Forms. This is demonstrated in the example form in the link below.

  1. Drag and drop two separate date/time fields into your form.

  2. Drag and drop a number field into your form to represent the time difference. In this example we will calculate this in minutes, however you can easily adapt these steps for the units that you want (e.g. minutes, days or seconds)

  3. In the data tab of the number field scroll down to the calculated value section and enter in the following JavaScript code. Note that you will need to adapt the code to match the API key of the two date fields in your form.
    โ€‹

    value = moment(data.endDate).diff(data.startDate, 'hours')

Did this answer your question?