javascript calculate days between dates

Solutions on MaxInterview for javascript calculate days between dates by the best coders in the world

showing results for - "javascript calculate days between dates"
Emilie
01 Mar 2020
1function calculateDaysBetweenDates(date1, date2) {
2  var oneDay = 24 * 60 * 60 * 1000;
3  var date1InMillis = date1.getTime();
4  var date2InMillis = date2.getTime();
5  var days = Math.round(Math.abs(date2InMillis - date1InMillis) / oneDay);
6  return days;
7}