how to calculate the number of days between two dates in javascript
JavaScript
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;
}function javascript (date1, date2) {
let oned = 24 * 60 * 60 * 1000;
return Math.ceil((date2 - date1) / oned);
}
function javascript(date1, date2) {
return new Date(date2 - date1).getDate() - 1
}
function javascript(date1, date2) {
return Math.ceil((date2 - date1) / 8.64e7);
}
Also in JavaScript:
- Title
- get value of hidden field jquery
- Category
- JavaScript
- Title
- for loop javascript
- Category
- JavaScript
- Title
- document ready js
- Category
- JavaScript
- Title
- how to know if a number has a decimal number js
- Category
- JavaScript
- Title
- is checked checkbox jquery
- Category
- JavaScript
- Title
- async iife
- Category
- JavaScript
- Title
- closure javascript
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- javascript clear file input
- Category
- JavaScript
- Title
- get day js
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- array javascript
- Category
- JavaScript
- Title
- how to make dynamic columns in jquery
- Category
- JavaScript
- Title
- angular observable subscribe and unsubscribe
- Category
- JavaScript
- Title
- faker js
- Category
- JavaScript
- Title
- Angularjs datetime
- Category
- JavaScript
- Title
- addEventListener
- Category
- JavaScript
- Title
- hello world javascript
- Category
- JavaScript
- Title
- find least common multiple javascript
- Category
- JavaScript
- Title
- how to make input type date supported on all browsers
- Category
- JavaScript
- Title
- datatables server side
- Category
- JavaScript
- Title
- how to make a div scrollable
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- how to run p5js in a particular section of page
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- includes()
- Category
- JavaScript
- Title
- array length for boolean in javascript
- Category
- JavaScript
- Title
- angular event scroll end of page
- Category
- JavaScript
- Title
- anguler test submit form
- Category
- JavaScript
- Title
- how to update jquery datatable row cell value
- Category
- JavaScript
- Title
- how to test fetch
- Category
- JavaScript
- Title
- event target javascript
- Category
- JavaScript
- Title
- Javascript change element class
- Category
- JavaScript
- Title
- how to have your discord bot send two message
- Category
- JavaScript
- Title
- how to use the foreach method in javascript
- Category
- JavaScript
- Title
- add variable numerically in javascript
- Category
- JavaScript
- Title
- faunadb ref
- Category
- JavaScript
- Title
- get radio button value javascript
- Category
- JavaScript
- Title
- dynamic loaded content can't find library jqury
- Category
- JavaScript
- Title
- iterate through nested object javascript
- Category
- JavaScript
- Title
- get value onChange from mat-select angular
- Category
- JavaScript
- Title
- compare string by several strings js
- Category
- JavaScript
- Title
- how to remove duplicate array object in javascript
- Category
- JavaScript
- Title
- change value of drop down using jquery
- Category
- JavaScript
- Title
- addeventlistener on document in react js
- Category
- JavaScript
- Title
- airbnb and eslint react native
- Category
- JavaScript
- Title
- Error: Can't resolve 'fs' webpack
- Category
- JavaScript
- Title
- changing attributes using javascript
- Category
- JavaScript
- Title
- chrome extension get current tab from popup
- Category
- JavaScript
- Title
- How to get the path to the file that required your module?
- Category
- JavaScript
- Title
- javascript capitalize words
- Category
- JavaScript
- Title
- create react app deployment heroku
- Category
- JavaScript
- Title
- functional component react
- Category
- JavaScript
- Title
- google sign in in firebase react
- Category
- JavaScript
- Title
- clear input field value javascript
- Category
- JavaScript
- Title
- delete session javascript
- Category
- JavaScript
- Title
- graphql react filtering
- Category
- JavaScript
- Title
- export apk react native
- Category
- JavaScript
- Title
- discord js get badge user
- Category
- JavaScript
- Title
- how to remove key value pair from object in javascript
- Category
- JavaScript
- Title
- clone object in js
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- angry professor javascript
- Category
- JavaScript
- Title
- how to run mocha tests on asynchronous functions in script
- Category
- JavaScript
- Title
- generate thumbnail of pdf using pf js
- Category
- JavaScript
- Title
- get url of page in background script
- Category
- JavaScript
- Title
- content disposition attachment javascript fetch download "excel"
- Category
- JavaScript
- Title
- how to use a fixed time zone in nodejs
- Category
- JavaScript
- Title
- close exit app react native
- Category
- JavaScript
- Title
- compare dates in js
- Category
- JavaScript
- Title
- fs writefile node
- Category
- JavaScript
- Title
- column.footer jquery
- Category
- JavaScript
- Title
- for of array javascript
- Category
- JavaScript
- Title
- get args nodejs
- Category
- JavaScript
- Title
- add val to array jquery
- Category
- JavaScript
- Title
- append before jquery
- Category
- JavaScript
- Title
- is sublime text a good editor
- Category
- JavaScript
- Title
- firestore update map
- Category
- JavaScript
- Title
- gulp-download-stream
- Category
- JavaScript
- Title
- javascript check if browser is ie
- Category
- JavaScript
- Title
- javascript array unique values
- Category
- JavaScript
- Title
- add value to array javascript
- Category
- JavaScript
- Title
- email regex javascript
- Category
- JavaScript
- Title
- find last element with class jquery
- Category
- JavaScript
- Title
- filter table search
- Category
- JavaScript
- Title
- array vowels js
- Category
- JavaScript
- Title
- interaction js drag anddrop
- Category
- JavaScript
- Title
- hide urls in .env in react app
- Category
- JavaScript
- Title
- javascript array contains object
- Category
- JavaScript
- Title
- javascript exercism.io bob solution
- Category
- JavaScript
- Title
- AWS SDK for javascript assumerole with proxy
- Category
- JavaScript
- Title
- how to capitalize a letter based on an index in javascript
- Category
- JavaScript
- Title
- add countdown timer to javascript quiz
- Category
- JavaScript
- Title
- how to make a screen recording software with js
- Category
- JavaScript
- Title
- array spread operator in javascript
- Category
- JavaScript
- Title
- create element javascript with id
- Category
- JavaScript
- Title
- adjust() js
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- for each js
- Category
- JavaScript
- Title
- hit enter button lick in js
- Category
- JavaScript