calculating dates and time

Last Updated: Apr 24, 2019 01:15PM CET

The date/time field can be used to perform simple date/time related arithmetic. This is useful when creating scheduling forms, calculating respondents age, duration of time taken to perform a task, number of days selected by respondents or other date related calculations.
The Date/Time field calculation can be carried out between 2 date/time fields, a single date field, or between a DateTime field and a Duration field, using the “Add Calculations” field. You can learn more about the Duration field in this article.

For calculation involving a DateTime field;

  • Include the DateTime field on your form, and select expected field options for your date and time fields. Learn more about the DateTime field.
  • Add calculation using the “Add calculations” field on your form. See the calculation article to learn more about adding a calculation to your form.

  • For a DateTime calculation, it is expected to specify the expected metric (date/time unit such as years, days, hours, minutes, second) in which the datetime calculation result will be displayed. If you do not specify an expected metric to display your result in, the results will automatically be displayed in hours.

  • To perform calculation between a date field and any other field, it is advisable to do this using the duration field. The duration field allows you to specify the metric in which the calculation will be carried out.
    PS - This does not specify the metric in which the result will be displayed. The expected result metric should be set from the calculation modal.

Calculate the number of days within a date range.

You can automatically calculate the number of days within a date range using the calculation field. This can be used for determining the number of days a person intends to carry out an action.

Example: You have a reservation form and will like to know how long a respondent will be reserving a spot through the form. You can do this using the DateTime calculation as explained below.

  • Add a date time field to your form

  • From the field options, set the field type to date only preferably.

  • Select the DateRange option from the date tab.

  • Click on the “Add Calculation” field to display the calculation modal.

  • The date field you have just added will be displayed at the left side of the modal where fields allowed for calculation are displayed. Click on the field so that it is selected for calculation

  • Select a preferred field to display your result.

  • Select a preferred metric in which result will be displayed in.

  • Click “Add” to include the calculation you have just carried out.

This will automatically display the time your respondent will be reserving a spot on the field you have chosen for display result. The result displayed is also dependent on the metric you have chosen to display your result. If you have chosen to display results in hours, the system automatically calculates the number of hours your respondent will be reserving a spot and display this result in the selected field to display result.


Calculate the difference between 2 date fields

You can perform a calculation between 2 DateTime fields. This is useful in determining the time taken to perform an action.

Example - You have a daily report form and will like to determine the difference between time in and time out in your form.

  • Input your date or time fields which your respondents will fill out on your form.

  • In the calculation modal, input your calculation as expected for the two date/time fields, select a field to display your result and select the metric you will like your answer to be displayed in.

  • Once your respondent has filled out the field, the system automatically does the calculation, giving you an answer in your preferred metric.

Another example of calculating two date fields is in determining the age of your respondent. In this case, you might not be needing the time field type.

  • Input your date field on your form to receive the date of birth of respondent.
  • Include another Date field on which you have enabled the option to Use Today as the default date. Enabling this option will automatically set the date for that field to the day your respondent accesses the form. If you do not want your respondents to know that you have automatically calculated their age, you can make this date field hidden or set to read-only so that your respondents do not access to edit the default value. Learn more about default values in this article.
  • ‚ÄčIn the calculation modal, subtract both date fields to get the age of the respondent.
  • Select a result field to display the result of the calculation. This field can also be hidden so that the respondents do not see the field. However, all hidden fields are still displayed on the responses page of your form.

From the above example, all your respondent has to do is input their date of birth and you will see the calculated value in the field selected to display the result, which can also be hidden or set to read-only such that respondents will not have access to it.

Do not forget to set the metric in which the result should be displayed. This means you can set the metric to display the number of hours a respondent has lived or the number of days a respondent has lived.

Subtracting or adding hours, days, months, years to a date field.

When/if the need arises for subtracting or adding hours, days, months, years to a date field, it is advisable to use the date time field together with the Duration field for this calculation. This field has the allowed metrics to fit a DateTime calculation such that you can select which metric you want your calculation to be carried out in.
This can not be easily done using a number field as the system can not automatically detect the right metric in which the calculation should be performed. But with a duration field, you can effectively carry out a calculation using preferred date/time related metric.

Example: subtracting a time inputted by a respondent by days, hours or minutes.
  • Add the DateTime field on your form. This should be depending on the calculation to be made.
  • Include your duration field, and select the preferred options/metric to be used in the calculation from the edit modal of the duration field. Also, you can add the default value or allow respondent input value depending on the structure of the data to be received.
  • In your calculation modal. Input your calculation such that duration field is subtracted from your date/time field. This means that your value for the duration field will be subtracted from the value for the date/time field which will be inputted by your respondent/ the default value you have set for the duration field.
  • Select another preferred field to display the result of the calculation.
  • Select the expected metric in which result will be displayed in. This is different from the metric you have selected in your duration field.
You can also use the option to "Use Now as default Date/Time" this option will automatically set the date/time the respondent accesses the form as the default date/time. Your respondent can also edit this except you have set the field to a read-only field or you have hidden the field.