Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to find difference between two dates from DatePicker Widgets?

Issue

I want to know how to find the difference between two dates using Date Picker widgets on Appsmith. Can anyone show me how to do this using the moment library?

Resolution

This solution demonstrates how to calculate the difference between two dates using two Date Picker widgets in Appsmith. The moment library is used for performing the date comparison.

To build this app, you start by adding two Date Picker widgets. You can choose to set default dates or add dates dynamically. Next, you drag and drop a text widget or any preferred widget that will display the calculated difference between the two dates.

To perform the operation, you use the moment library by writing the code: moment(DatePicker2.selectedDate).diff(DatePicker1.selectedDate, "days"). The method diff() is used to calculate the difference between the two dates in days, and the result is displayed in the text widget.

Overall, this solution provides an easy and efficient way to calculate the difference between two dates in Appsmith.