All Collections
Asite AppBuilder
AppBuilder Sample Scripts
Calculate difference in number of days between two dates selected by user
Calculate difference in number of days between two dates selected by user

This is an AppBuilder Sample Script.

Updated over a week ago

Suppose there are two 'Datepicker' fields with the field name 'Start_Date' and 'End_Date' respectively. There is another textbox field with the field name 'Days_Difference' in which the difference value should appear based on the 'Start_Date' and 'End_Date' selected by the user. In such a case, you can use the drag and drop code editor to define a condition like below upon the 'onChange' event of 'Days_Difference' control:

Here are the steps to understand how you can define such a condition:
โ€‹

1. From the left panel, click on the option 'Custom Functions'. Select the fifth block called 'Set Value' and drag it to center of the editor.

2. In the 'Control Name', select 'Days_Difference'.

3. From the left panel, click on the option 'Custom Functions', Select the block for 'Get Date Difference' and replace block for 'Value' field with selected block.

4. Select the 'End_Date' and 'Start_Date' control names in 'Date1' and 'Date2' fields for 'Get Date Difference' block respectively.

5. Once done, click 'OK' (at bottom right) to save the changes and exit the code editor, then save / publish the form design as needed. Once the form design is published and executed, the changes will be applicable for the new forms created under the related form type.



Did this answer your question?