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 :: react conditionally disable button 
Javascript :: validate mobile number in javascript 
Javascript :: creating array of objects usinng reduce js 
Javascript :: importing json file in javascript 
Javascript :: mongo updatemany query 
Javascript :: split decimal value in javascript 
Javascript :: jspdf pdf from html 
Javascript :: joi object id validation 
Javascript :: javascript mousedown mouseup 
Javascript :: square root numbers in array javascript 
Javascript :: use eslint in vscode 
Javascript :: reactjs cdn 
Javascript :: app.use public 
Javascript :: javascript make alert sound 
Javascript :: gsap pin scrolltrigger 
Javascript :: unary operator javascript 
Javascript :: javascript truncate decimal without rounding 
Javascript :: array sort by two properties 
Javascript :: expo react native send image to api 
Javascript :: check online status javascript 
Javascript :: preload javascript 
Javascript :: this.props.history.location.push 
Javascript :: @react-google-maps/api npm 
Javascript :: toast message angular 
Javascript :: Error: Unable to resolve module ./index from 
Javascript :: ubuntu 18.04 nodejs insatll 
Javascript :: how to change materil ui divider coloer 
Javascript :: javascript round to 8 decimal places 
Javascript :: deserialize json jquery 
Javascript :: firebase where or 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =