How to get the number of days between 2 dates in JavaScript

1 Answer

0 votes
function getDaysBetween2Dates(startDate, endDate) {
  	const milliseconInADay = 24 * 60 * 60 * 1000;

  	return Math.round(Math.abs(endDate - startDate) / milliseconInADay);
}

console.log(getDaysBetween2Dates(new Date('2022-04-03'), new Date('2022-04-08')));

  
  
  
  
/*
run:
  
5
  
*/

 



answered Apr 8, 2022 by avibootz

Related questions

...