How to built that? So that we can pick x and y dates and we get duration of those days and hours results.
CalcHub Answered question March 8, 2023
Hello.
You can use the formula:
const date1 = new Date(x[1]); const date2 = new Date(x[2]); const days = daysBetween(date1, date2); y[1] = days; function daysBetween(date1, date2) { const date1Ms = date1.getTime(); const date2Ms = date2.getTime(); const differenceMs = Math.abs(date1Ms - date2Ms); const days = Math.floor(differenceMs / (1000 * 60 * 60 * 24)); return days; }
where x[1] – start date, x[2] – finish date, y[1] – result.
You can look the example by link https://calchub.xyz/days-between-dates/
CalcHub Answered question March 8, 2023