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 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

get all date between two dates in javascript

// Returns an array of dates between the two dates
function getDates (startDate, endDate) {
  const dates = []
  let currentDate = startDate
  const addDays = function (days) {
    const date = new Date(this.valueOf())
    date.setDate(date.getDate() + days)
    return date
  }
  while (currentDate <= endDate) {
    dates.push(currentDate)
    currentDate = addDays.call(currentDate, 1)
  }
  return dates
}

// Usage
const dates = getDates(new Date(2013, 10, 22), new Date(2013, 11, 25))
dates.forEach(function (date) {
  console.log(date)
})
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 :: traversing 2d array javascript 
Javascript :: prompt dentro de una funcion javascript 
Javascript :: sort used in price high and low using angular 
Javascript :: if this then this, else that 
Javascript :: .loads with whole json file 
Javascript :: how to put condition on pagination material table 
Javascript :: html5 javascript json vertical colom grap 
Javascript :: jsdoc run for all files in folder 
Javascript :: Laravel summernote HTML output 
Javascript :: Multiple Locale Support momentjs 
Javascript :: pass mltiple valuesthorugh context in react 
Javascript :: javascript How to show array content in output window 
Javascript :: google chrome extension v3 react content security policy issue 
Javascript :: how to change css of menu when scrolling 
Javascript :: call method from parent 
Javascript :: angular chart js graph legend colors 
Javascript :: Relaxed "angularjs" style expression parsing missing in vue 
Javascript :: check if Popups and Redirects are allowed 
Javascript :: mutexify 
Javascript :: fetch 500 internal server error 
Javascript :: p5 filter 
Javascript :: Using Bind() With BuiltIn JavaScript Function 
Javascript :: assign single value to multiple variables in React js Or javacript 
Javascript :: Saving dependencies in your node package.json syntax 
Javascript :: Constructor for blockchain 
Javascript :: A Node Module For ReactJS 
Javascript :: confirming the end javascript 
Javascript :: checkbox null value javascript 
Javascript :: How to Solve the Parking Lot Challenge in JavaScript 
Javascript :: react use last state 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =