How to Calculate a Date Range
With the Calculated Field from the JetFormBuilder WordPress plugin, you can automatically calculate the difference between two dates. This is especially useful for booking forms, availability checks, and any scenario where duration is a factor.
Table of Contents:
- Calculate the Difference Between Two Date Fields in Days
- Calculate the Difference Between Two Date Fields in Months
- Calculate the Difference Between Two Date Fields in Years
- Calculate the Number of Days Between the Date Field and the Current Day
- Calculate Date + X Days
- Calculate Month + X Months
- Calculate Year + X Years
Calculate the Difference Between Two Date Fields in Days
Let’s proceed to WordPress Dashboard > JetFormBuilder > Forms and click the “Add New Form” button or the “Edit” button for an already existing form.
As we know from the Calculated Field article, the Calculated Field supports simple and more complex mathematical operations for the numeric values. However, in this tutorial, we will focus on calculating the values from Date Fields.
We add two Date Fields named “start_date” and “end_date”. In the Field tab, enable the Is Timestamp toggle.

Then, add the Calculated Field and enter the FIELD LABEL. Inside the Calculated Field, paste the following formula:
(%end_date|T% - %start_date|T%) / %CT::Day_In_Sec%
Here, “end_date” stands for the FORM FIELD NAME of the Date Field where the end date is selected, and “start_date” stands for the name of the Date Field where the start date is selected.

When we save the form and proceed to the frontend and select July 10, 2025, for the start date and July 15, 2025, for the end date, we get “5” as a result of the difference between the two Date Fields.

Calculate the Difference Between Two Date Fields in Months
Now, we come back to the form settings and continue to use the same “start_date” and “end_date” Date Fields, but to count the difference in months, we need the following formula to be added to the Calculated Field:
Math.round((%end_date|T% - %start_date|T%) / %CT::Month_In_Sec%)
As in the previous case, “end_date” refers to the Date Field where users choose the end date, while “start_date” refers to the field used to select the start date.

So, click the “Save” button and proceed to the frontend. When we select the start date in July and the end date in October, we get “3” months in the Calculated Field.

Calculate the Difference Between Two Date Fields in Years
In case you need to count the years between two Date Fields, use the following formula for the Calculated Field in the form editor:
Math.round((%end_date|T% - %start_date|T%) / %CT::Year_In_Sec%)

The “end_date” field represents the Date Field where the end date is selected, and “start_date” indicates the field used for choosing the start date.
After saving the form and proceeding to the frontend, we choose dates in different years, such as 2024 and 2026, and we obtain the correct “2” years value in the Calculated Field.

Calculate the Number of Days Between the Date Field and the Current Day
Let’s focus on the case when we need to calculate the number of days between the date selected in the Date Field and the current date.
For that, we proceed to the form editor and add a Hidden Field to retrieve the current date. In the FIELD VALUE, select the “Current Date” option. Put “U” in the FORMAT field to get the timestamp format.

Also, we added a Date Field with the Is Timestamp toggle on.
Then, we need the following formula to be added to the Calculated Field:
%date_field|T% ? Math.round((((%current_date% * 1000) - %date_field|T%) / %CT::Day_In_Sec%) * -1) : 0

In this case, “current_date” refers to the Hidden Field where we retrieve the current date, while “date_field” refers to the field used to select the date.
Save the form and move to the frontend to check how it works. We submitted the form at midday on July 2 (so it is the current date for us), and in the Date Field, we selected July 20. In the Calculated Field, we obtained the correct result of “18”.

Calculate Date + X Days
Here, we focus on the form settings where we sum the number of days with the Date Field in the form and display the result in the Calculated Field.
We need to open the form editor and add a Date Field for the dates and a Radio Field to select the number of days to be added to our Date Field.

In the Calculated Field, we add the following formula:
+'%days%' * %CT::Day_In_Sec% +%date_field|T%
Here, “days” is the name assigned to the Radio Field used for selecting the number of days, and “date_field” is the name given to the field for the date.

In the Field tab of the Calculated Field, choose the “as Date” option for the VALUE TYPE input. In the newly appeared DATE FORMAT, set the desired format; in our case, we use the “DD-MM-YYYY”.
When we save the form settings, go to the frontend, select the date (July 10, 2025, for example), and the number of days from the Radio Field (we selected “5”), we get the correct date: “15-07-2025”.

Calculate Month + X Months
Let’s move back to the form edit page.
In case we need to sum months, we need the Date Field and Radio Field for selecting the month number.
The formula for the Calculated Field should be a bit different:
+'%months%' * %CT::Month_In_Sec% +%date_field|T%
In this case, “months” refers to the Radio Field where users choose the number of months, while “date_field” refers to the field used to select the date.

Ensure that the “as Date” option is chosen for the VALUE TYPE. You can use the needed format for the date. In this case, to focus on counting months, we use the “MM-YYYY” format.
When we save the form, move to the frontend, and select the date in July 2025, and “5” months from the Radio Field, in the Calculated Field, we get the correct answer of “12-2025”.

Calculate Year + X Years
When we need to sum the years from the Date and Radio Fields, we put the following formula in the Calculated field on the form editing page:
+'%years%' * %CT::Year_In_Sec% +%date_field|T%
In this setup, the “years” field is designated for selecting the number of years, and the “date_field” field is used for selecting the date.

Make sure that the “as Date” option is chosen for the VALUE TYPE. You can use the desired format for the date. In this tutorial, we focus on counting years using the “YYYY” format.
After saving the form and checking it on the frontend, we select the date in 2025 and choose “10” in the Radio Field. In the Calculated Field, we obtain the correct result of “2035”.

That’s it. Now you know how to calculate various date ranges with the help of the Calculated Field from the JetFormBuilder plugin for WordPress sites.