Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript difference between two dates

const date1 = new Date('7/13/2010');
const date2 = new Date('12/15/2010');
console.log(getDifferenceInDays(date1, date2));
console.log(getDifferenceInHours(date1, date2));
console.log(getDifferenceInMinutes(date1, date2));
console.log(getDifferenceInSeconds(date1, date2));

function getDifferenceInDays(date1, date2) {
  const diffInMs = Math.abs(date2 - date1);
  return diffInMs / (1000 * 60 * 60 * 24);
}

function getDifferenceInHours(date1, date2) {
  const diffInMs = Math.abs(date2 - date1);
  return diffInMs / (1000 * 60 * 60);
}

function getDifferenceInMinutes(date1, date2) {
  const diffInMs = Math.abs(date2 - date1);
  return diffInMs / (1000 * 60);
}

function getDifferenceInSeconds(date1, date2) {
  const diffInMs = Math.abs(date2 - date1);
  return diffInMs / 1000;
}
Comment

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

get the difference between two dates js

const date1 = new Date('7/13/2010');
const date2 = new Date('12/15/2010');
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

check a date is between two dates in javascript

const dateCheck = (from, to, check) => {
    let fDate,lDate,cDate;
    fDate = Date.parse(from);
    lDate = Date.parse(to);
    cDate = Date.parse(check);
    if((cDate <= lDate && cDate >= fDate))  return true
    return false;
}
dateCheck("02/05/2021","02/09/2021","02/07/2021")
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 :: circular object array 
Javascript :: How to add pop-up confirmation in angular typescript. 
Javascript :: test driven development javascript 
Javascript :: js regex find newlines 
Javascript :: Create & Download PDF from Byte[] Array using jQuery AJAX 
Javascript :: stack array in localStorage 
Javascript :: javascript read all cookies 
Javascript :: Javascripti functions accepting Flask parameters to display a PDF file with Adobe Embed API 
Javascript :: phaser grid align 
Javascript :: phaser set x y 
Javascript :: phaser mixed animation 
Javascript :: regular expression a-z and 0-9 
Javascript :: Is he gonna survive 
Javascript :: Opposites attract 
Javascript :: ray intersection js 
Javascript :: getauth firebase admin node.js 
Javascript :: javascript list all elements in set 
Javascript :: express-js 
Javascript :: ... in javascript 
Javascript :: how to call function from another component in vue js 
Javascript :: how to add google map in react js 
Javascript :: Remove escape characters from JSON Data 
Javascript :: javascript unicode character 
Javascript :: fuzzy search javascript 
Javascript :: Material-ui account circle icon 
Javascript :: function in javascript 
Javascript :: for loop in react native 
Javascript :: how to remove an element from an array javascript 
Javascript :: what is let js 
Javascript :: regex for ipv4 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =