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

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 :: js string search 
Javascript :: nodejs powershell process env 
Javascript :: brightness javascript onload 
Javascript :: how to format money as currency string 
Javascript :: email regular expression 
Javascript :: react-native shadow generator 
Javascript :: next js install swr 
Javascript :: how to make a if loop happen one 
Javascript :: Creating new array from old array without impacting old array 
Javascript :: adonisjs sync method 
Javascript :: get last element from div javascript 
Javascript :: capture image from video element 
Javascript :: javascript current date 
Javascript :: remove file from input type file jquery 
Javascript :: empty text in all class jquery 
Javascript :: how to change the font family using jquery 
Javascript :: get lat long from zip code in google places api 
Javascript :: gdscript emit signal 
Javascript :: react-native array.filter by index arrow function 
Javascript :: javascript square root 
Javascript :: how to change specific object in array javascript 
Javascript :: set background image in material ui 
Javascript :: divide array of objects to 4 arrays js 
Javascript :: how to pronounce allele 
Javascript :: javascript text to speech 
Javascript :: regex for no whitespace at the beginning and end 
Javascript :: javascript get data attribute of selected option 
Javascript :: style hover js 
Javascript :: react js font awesome icon not rendering 
Javascript :: remover clase jquery 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =