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.

A form calculation to add days to a date in Jotform Form Builder

Example:

FormulaaddDays(Date, Days to add)
Date2030-01-01
Days to add5
ResultSun Jan 06 2030

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.

Performing Date and Time Calculations Image-1

Example:

FormulaTo – From
From2030-01-01 00:00
To2030-01-02 12:00
Result1.50

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:

UnitFormula
YearsDays / 365
MonthsDays / 30
HoursDays * 24
MinutesDays * 1440
SecondsDays * 86400

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:

UnitFormula
Yearsfloor(Days / 365)
Monthsfloor((Days % 365) / 30)
Daysfloor(Days % 365 % 30)

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:

Support Forum: https://www.jotform.com/answers/

Contact Jotform Support: https://www.jotform.com/contact/

Send Comment:

Jotform Avatar
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comments:

  • Brigitte - Profile picture
  • Susan Jeffers - Profile picture
  • Simon Colyer - Profile picture
  • Richard Godinez - Profile picture
  • Enchanted Fredericksburg Ranch - Profile picture
  • Sharon Owen - Profile picture
  • Ria - Profile picture
  • Ayman - Profile picture
  • Sailing Singles Admin - Profile picture
  • Lee_Walter - Profile picture
  • Bethany - Profile picture
  • stevehill2582 - Profile picture
  • aaronchan - Profile picture
  • WDJH - Profile picture
  • uqhalls - Profile picture
  • Anthony  - Profile picture
  • Haider Abbas - Profile picture
  • HICKY - Profile picture
  • POME3790 - Profile picture