Perform Calculations on Date / Time Fields

Prev Next

Date and Time elements can be used in calculations for a variety of circumstances such as calculating the number of days of a reservation or calculating a user's age. Learn more about the Calculation Element.

Date and Time calculations use Epoch Unix timestamps which are represented as a number, specifically the number of milliseconds since January 1, 1970, Coordinated Universal Time (UTC). Meaning when calculating the difference between times you will need to divide the result in order to get the increment of time you are looking for. For example, in the 'Hours' bullet below, the difference between the end and start times is divided by 3,600,000 (the number of milliseconds in 1 hour).

You will need to divide by the following numbers to get the applicable length of time in your calculation. Information on how to set up these formulas can be found in the instructions below.

  • Hours: divide by 3600000

    • Example Formula: ROUND_UP(({ELEMENT:End_Time} - {ELEMENT:Start_Time) / 3600000)

  • Days: divide by 86400000

    • Example Formula: ({ELEMENT:Date_of_Departure} - {ELEMENT:Date_of_Arrival}) / 86400000

  • Years: divide by 31540000000

    • Example Formula: ROUND_DOWN(({ELEMENT:Current_Date} - {ELEMENT:Date_of_Birth}) / 31540000000)

Calculate Time

In this example, we are calculating the difference between a start time and an end time within a day. The result displays the amount of time in hours.

  1. Create or edit an existing form and navigate to the Builder tab Builder tab at the top of the screen.

  2. Add your Time Elements to the form Time Elements on Builder tab.

  3. Add a Calculation ElementCalculation Element Type.

  4. Add a Label for the element Calculation Label field.

  5. Under the Calculation field, select a Rounding option Round button on Calculation box.

    • ROUND: Will round the result to the specified number of decimal places

    • ROUND_UP: Will round up the result to the nearest whole number

    • ROUND_DOWN: Will round down the result to the nearest whole number

  6. Click inside the parentheses () and select the end time element from the Insert Element drop-down Insert Element drop-down.

  7. Add a minus sign ( - ) after the element bracket Minus sign after element.

  8. Click Insert Element and select the start time element Insert Element drop-down.

  9. Add a divide sign ( / ) after the parentheses Division sign after element bracket.

  10. Enter the following number to calculate the time in hours: 3600000Calculation for hours.

    Note: If you are using the ROUND function, you will need to add a comma and how many decimal places you would like the calculation to display. For example, 3600000, 2 will show two decimal places. If you do not want to show decimal places, we recommend using the ROUND_UP or ROUND_DOWN functions to round to the nearest whole number.

  11. Add parentheses to the start of the formula (after the rounding option) and to the end of the formula Calculation formula example.

  12. In the Calculation Content field, add any additional context for end users such as the word "hours" Calculation Content field.

  13. Click the Save button in the top right corner Save button.

  14. Your form will now calculate the total number of hours entered Time Calculation preview.

  15. If needed, you can add Conditional Logic based on how many hours a user has selected. In the example below, we set up a Calculation element that will charge users a specific rate if the reservation is 4 hours or less. We also set up a separate calculation element that will charge users a different rate if the reservation is more than 4 hours. Calculation Condition Example. Condition Example continued.

  16. The Total Reservation Cost will now reflect the user's selections Reservation Cost Hours Example.

Calculate Days / Days and Time

In this example, we are using a start date and an end date and calculating the amount of time between these different dates to display the amount of time in days as a result.

  1. Create or edit an existing form and navigate to the Builder tab Builder tab at the top of the screen.

  2. Add your Date elements or Date and Time elements to the form Date Elements.

  3. Add a Calculation ElementCalculation Element Type.

  4. Add a Label for the element Calculation Label field.

  5. In the Calculation field, click Insert Element and select the end date element Insert Element drop-down.

  6. Add a minus sign after the element bracket Minus sign after the element bracket.

  7. Click Insert Element and select the start date element Insert Element Date of Arrival.

  8. Add parentheses around the elements Parentheses around the formula.

  9. After the last parenthesis, add a divide sign ( / ) and the number 86400000 to calculate the number of daysDividing by number to calculate days.

  10. In the Calculation Content field, add any additional context for end users such as the word "days" Calculation Content textbox with total days of reservation noted.

  11. Click the Save button in the top right corner Save button.

  12. Your form will now calculate the total number of days entered Preview of the Date Calculation.

    Note: If you use the Date and Time element, the result will display decimal points for the number of hours.Date and Time calculation preview.You can use the ROUND_UP or ROUND_DOWN functions to round the result to the nearest whole number.PADS Calculation dates rounding.

  13. If needed, you can add Conditional Logic based on how many days a user has selected. In the example below, we set up a Calculation element that will charge users a specific rate if the reservation is 2 days or less. We also set up a separate calculation element that will charge users a different rate if the reservation is more than 2 days. Calculation Condition Example Days Calculation Condition Example Days continued.

  14. The Total Reservation Cost will now reflect the user's selections Example Cost for Number of Days.

Calculate Years

In this example, we are calculating the difference in time between the current date and an entered date. This can be used to calculate a user's age.

  1. Create or edit an existing form and navigate to the Builder tab Builder tab at the top of the screen.

  2. Add your Date Elements to the form Date elements for the current date and date of birth.

    Note: If you want one of the date elements to reflect the current date, ensure the Default Date field is set to Form Viewed and toggle on Read Only. Default Date field on the Calculation element.

  3. Add a Calculation ElementCalculation Element Type.

  4. Add a Label for the element Calculation Label field.

  5. Under the Calculation field, select a Rounding option Round button on the calculation box.

    • ROUND: Will round the result to the specified number of decimal places

    • ROUND_UP: Will round up the result to the nearest whole number

    • ROUND_DOWN: Will round down the result to the nearest whole number

  6. Click inside the parentheses () and select the current date element from the Insert Element drop-down Insert Current Date element from the drop-down.

  7. Add a minus sign ( - ) after the element bracket }Minus Sign after the element bracket.

  8. Click Insert Element and select the other date elementDate of Birth selected in the Insert Element drop-down.

  9. Add a divide sign / after the parentheses Divide Sign after the element.

  10. Enter the following numbers to calculate the time in years: 31540000000Calculation number for years.

    Note: If you are using the ROUND function, you will need to add a comma and how many decimal places you would like the calculation to display. For example, 31540000000, 1 will show one decimal place. If you do not want to show decimal places, we recommend using the ROUND_UP or ROUND_DOWN functions to round to the nearest whole number. For example, instead of showing someone's age as 30.6 years, it would display as 31 or 30.

  11. Add parentheses () to the start of the formula (after the rounding option) and to the end of the formula Calculation Year Formula.

    Note: The example formula above is: ROUND_DOWN(({ELEMENT:Current_Date} - {ELEMENT:Date_of_Birth}) / 31540000000). Replace the Element names with the name of the elements in your form.

  12. In the Calculation Content field, add any additional context for end users Calculation Content for the age in years.

  13. Click the Save button in the top right corner Save button.

  14. Your form will now calculate the total number of years Preview of the calculation for years.

  15. If needed, you can add Conditional Logic based on a user's age. In the example below, we set up a Calculation element that will charge users a specific rate if they are age 55 or older. We also set up a separate calculation element that will charge users a different rate if they are younger than 55. Calculation Condition Year Example. PADS Calculation Condition Year Example continued.

  16. The Total Registration Cost will now reflect the user's age selection Condition Year Preview.