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

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 :: javascript foreach 
Javascript :: upsert mongoose 
Javascript :: redirect angular 
Javascript :: install aos in react 
Javascript :: javascript toggle value 
Javascript :: javascript hasclass 
Javascript :: setlocalstorage 
Javascript :: javascript to string 
Javascript :: string to char array in javascript 
Javascript :: angular serve on different port 
Javascript :: jquery datepicker re initialize 
Javascript :: generate random 6 numbers in javascript 
Javascript :: get alert after using ajax 
Javascript :: search box enter key javascript 
Javascript :: Math prime js 
Javascript :: show div with jquery 
Javascript :: js compare 2 arrays for unique values 
Javascript :: give the player an item skript 
Javascript :: toobject() javascript 
Javascript :: how to set validation for email in javascript 
Javascript :: jquery delay to call function 
Javascript :: javascript log Time from Date 
Javascript :: Nazmul 
Javascript :: set an attribute background image javascript 
Javascript :: nodejs check if variable is undefined 
Javascript :: unexpected token export type react bottontab navigation 
Javascript :: neo4j delete relationship nodes 
Javascript :: remove character at index from string javascript 
Javascript :: jsonobject gradle dependency 
Javascript :: slug generator javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =