Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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  );
Comment

javascript calculate days between dates

function calculateDaysBetweenDates(date1, date2) {
  var oneDay = 24 * 60 * 60 * 1000;
  var date1InMillis = date1.getTime();
  var date2InMillis = date2.getTime();
  var days = Math.round(Math.abs(date2InMillis - date1InMillis) / oneDay);
  return days;
}
Comment

js get difference in days

const date1 = new Date('19/1/2021');
const date2 = new Date('20/1/2021');
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); 
console.log(diffTime + " milliseconds");
console.log(diffDays + " days");
Comment

javascript Find the number of days between two days

const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000)

dayDif(new Date("2020-10-21"), new Date("2021-10-22"))
// Result: 366
Comment

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
Comment

calculate days between two dates in javascript

<input id="first" value="25/2/2021"/>
<input id="second" value="26/2/2021"/>
Comment

PREVIOUS NEXT
Code Example
Javascript :: read file node 
Javascript :: number to char js 
Javascript :: material-ui textfield underline hide 
Javascript :: js split string on capital letter second 
Javascript :: swiper js cdn 
Javascript :: js parse string to html elemen 
Javascript :: hide search in datatable 
Javascript :: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 
Javascript :: javascript style background color 
Javascript :: disable right click jquery 
Javascript :: jquery get the length of input text 
Javascript :: settimeout jquery 
Javascript :: 1 line uuid 
Javascript :: jquery close bootstrap model 
Javascript :: disable right click 
Javascript :: javascript audio stop 
Javascript :: regex to allow only numbers letters and hyphen 
Javascript :: react.js installation 
Javascript :: javascript how to check for an empty object 
Javascript :: yup email validation 
Javascript :: latest react version npm 
Javascript :: javascript to redirect to another page after 5 seconds 
Javascript :: how to limit decimal places in javascript 
Javascript :: how to sort string aray in ts 
Javascript :: how to trigger change of summernote 
Javascript :: javascript function to generate random alphanumeric string 
Javascript :: arrow not showing react slick 
Javascript :: how to set name attribute in jquery 
Javascript :: enzyme adapter react 17 
Javascript :: remove session storage 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =