How do I get the number of days between two dates?
Last Update: November 10, 2017
Here are the steps on how to get the number of days between two dates:
- Open the form in
design mode.
- Add two Date controls to the form design area named datFrom and datTo.
- Add TexBox control named txtDayDiff to present the difference between the two dates.
- Select the datFrom or datTo control.
- In the
Rules pane, click on the Add icon to add a new rule, the
Rule Manager dialog will open.

- Add a new rule at Date1 control as follows:
A. Update the Rule Name as desired.
B. Change the Rule Type to Action.
C. Change the Event Type to Onchange. Check "Execute if event triggered only on this control".
D. In the Condition section, type the following:
getValue(datFrom) != '' && getValue(datTo) != ''
E. In the Action section, type the following script:
setValue(txtDayDiff, calculateDaysExcludedDays(getValue(datFrom), getValue(datTo),[],[]))
F. Click on the
Save button to save the rule.
Note: You can use
Assistance Panel to help you adding functions and related parameters, form variables and form controls to
Conditions and/or
Actions sections. - Test the form by clicking on the
Preview button in the
View group.