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 :: what is console working for in js 
Javascript :: make triangle with threejs 
Javascript :: buffer image 
Javascript :: javaScript Math.log() Method 
Javascript :: sveltekit redirect 
Javascript :: discord role giver 
Javascript :: python to java script 
Javascript :: how to add a function in javascript 
Javascript :: pattern printing in javascript 
Javascript :: react custom hooks 
Javascript :: select all checkbox in angular 
Javascript :: buttons js before submit 
Javascript :: browser support fetch api 
Javascript :: fixed header on scroll vuejs 
Javascript :: jquery check if eleme 
Javascript :: Get home directory in nodejs windows 
Javascript :: module parse failed: unexpected character ' (1:0) you may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. see https://webpack.js.org/concepts#loaders 
Javascript :: define conastant js 
Javascript :: recorrer array javascript 
Javascript :: public static void main(dsjjsdds, jdnjd, jsndjsd, isjdjsd, sjdijs, skjdks_+) __ osakd___ +++ 
Javascript :: react-metismenu-router-link 
Python :: tkinter how to make a root non rezizable 
Python :: pip3 upgrade 
Python :: remove all pyc files 
Python :: python exception with line number 
Python :: how to return PIL image from opencv 
Python :: check the os in python 
Python :: enumerate zip python 
Python :: python get line number of error 
Python :: change tkinter window name 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =