How to calculate the number of days between two dates in JavaScript

1 Answer

0 votes
function days_difference(startDate, endDate) {
    const oneDay = 24 * 60 * 60 * 1000; // hours * minutes * seconds * milliseconds
    
    return Math.round((endDate - startDate) / oneDay);
}
 
 
const dt1 = new Date('11/04/2019')
 
const dt2 = new Date('11/07/2019')
 
console.log(days_difference(dt1, dt2));
 
 
 
 
/*
run:
       
3
     
*/

 



answered Nov 4, 2019 by avibootz
edited Jun 12, 2022 by avibootz

Related questions

...