Answers for "get number days between 2 dates javascript"

5

How do I get the number of days between two dates in JavaScript

let today = new Date().toISOString().slice(0, 10)

const startDate  = '2021-04-15';
const endDate    = today;

const diffInMs   = new Date(endDate) - new Date(startDate)
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);


alert( diffInDays  );
Posted by: Guest on August-07-2021
2

javascript difference between two dates in days

const diffDays = (date, otherDate) => Math.ceil(Math.abs(date - otherDate) / (1000 * 60 * 60 * 24));

// Example
diffDays(new Date('2014-12-19'), new Date('2020-01-01'));   // 1839
Posted by: Guest on July-03-2020
-2

calculate days between two dates in javascript

<input id="first" value="25/2/2021"/>
<input id="second" value="26/2/2021"/>
Posted by: Guest on February-25-2021

Code answers related to "get number days between 2 dates javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language