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 native scaling font 
Javascript :: copyright js 
Javascript :: load +main.js with system.import 
Javascript :: javascript replace doublequote with empty string 
Javascript :: nuxt js emit event 
Javascript :: javascript remove empty object items 
Javascript :: javascript rotate image canvas 
Javascript :: jquery search for string in text 
Javascript :: string repeat codewars javascript 
Javascript :: word count javascript 
Javascript :: javascript wait for multiple promises 
Javascript :: express get raw path 
Javascript :: react onclick div 
Javascript :: livewire upload progress 
Javascript :: javascript display 2 number after comma 
Javascript :: react native position text in center of view 
Javascript :: check if string matches regex js 
Javascript :: get data from url javascript 
Javascript :: set variable to object without editing old object js 
Javascript :: javascript newline in alert box 
Javascript :: nodejs express hot reload 
Javascript :: javascript add function to onchange event 
Javascript :: open a particular slide on click button in owl carousel 
Javascript :: request body empty express 
Javascript :: javascript sum array of objects by key 
Javascript :: set focus on load javascript 
Javascript :: js get option value 
Javascript :: update style with javascript react components 
Javascript :: how to get the max value of two variables in math 
Javascript :: Navbar Componet Nextjs 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =