# Performing Date and Time Calculations

September 6, 2023

This guide shows some useful tips when performing date calculations using the Date Picker form element and the Form Calculation widget. It’s important that you’re comfortable working with Form Calculation. 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 Number, indicated by the [0-9] label, for the calculations to work.

## Adding or Subtracting Days to a Date

You can directly add or subtract days to a date in Form Calculation. The result will be a sequential serial number representing a date. To convert it back to a readable date format, use the dateString() function.

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.
END OF YEAR SALE
Save 50%

## ON ANNUAL JOTFORM PLANS

Offer does not apply to Jotform Enterprise

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: