Answers for "get number of days between two dates in year-month-day format in 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
0

javascript date 3 months ago

var someDate = new Date(); // add arguments as needed
someDate.setTime(someDate.getTime() - 3*28*24*60*60);
// assumes the definition of "one month" to be "four weeks".
Posted by: Guest on May-04-2020

Code answers related to "get number of days between two dates in year-month-day format in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language