Hi Usman,
The value returned by the DatePicker component is a Javascript Date object which contains the date value in milliseconds. So, it needs to be “convinced” to provide the desired value.
Try using this routine to calculate the difference.
export function date_diff_indays(date1, date2) {
let dt1 = new Date(date1);
let dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}
Call the routine like this:
let diff = date_diff_indays(endDate, startDate);
I hope this helps,
Yisrael