Performing Date and Time Calculations

February 22, 2024

This guide shows some useful tips when performing date calculations using the Date Picker form element and Form Calculation widget. Working comfortably with Form Calculation helps. To learn more, see Form Calculation.

Notes

• Form Calculation converts dates to sequential serial numbers (datetime) so they can be used in calculations. By default, 1970-01-01 (00:00:00 UTC) is 0, and 2095-01-23 (12:00:00 UTC) is 45678.50 because it is 45,678 days and 12 hours from January 1, 1970 midnight.
• Form fields added in Form Calculation must be set to numeric indicated by the trailing [0-9] label for the calculations to work.

Adding or Subtracting Days to a Date

You can add or subtract days to a date in Form Calculation using the addDays() and subtractDays() functions respectively. The result will be a date in “D M d Y” format, like Sun Jan 06 2030.

Example:

You can also add a specified number of units to a particular date in Jotform Tables using the DATEADD function. To learn more, see Advanced Formula: Date Functions.

Getting the Difference Between Two Dates

To get the difference between two dates, subtract one Date Picker from another. The result will be the number of days, in decimals, between the two dates.

Example:

To get the absolute result regardless of the dates’ order, use abs() in Form Calculation. You can also get the difference between two dates in your specified units in Jotform Tables using the DATETIME_DIFF function. To learn more, see Advanced Formula: Date Functions.

Converting Days to a Different Unit of Time

Date calculations in the Form Calculation widget return the result in days units. To turn it, or any number, into a different unit of time, add a Form Calculation widget to your form and set the unit’s formula from the following table:

Note: Rounded conversion factors are used for years and months. For other values, see Conversion Factors: Time.

Converting Days to Years, Months, and Days

Supposing, you have the number of days, and now, you want to convert this number to a years, months, and days format. To set it up, add three Form Calculation widgets to your form and use the following formula for each:

Notes

• Rounded conversion factors are used for years (365) and months (30). For other values, see Conversion Factors: Time.
• To use the modulo operator, use your keyboard to type in the percent (“%”) symbol in Form Calculation. The modulo operation returns the remainder of a division.
• The floor() function rounds the result down to the nearest integer.
• You can test the results in this demo form.
Contact Support:

Our customer support team is available 24/7 and our average response time is between one to two hours.
Our team can be contacted via: