Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

calculate date difference in javascript code example

Example 1: subtracting two date objects in javacript

function findDayDifference(date1, date2) {
	// always round down
  return Math.floor((Math.abs(date2-date1))/(1000*60*60*24));
}

Example 2: 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

Tags:

Javascript Example

Related

long array in python code example declaring as variable in java code example 'charmap' codec can't decode byte 0x8f in position 123: character maps to <undefined> code example how to move string to next line in javascript code example NSLocalizedString not working code example closure scope javascript code example SVC(kernel='linear', class_weight='balanced') code example pandas rows with only a specific value in column code example document ready js pure code example array state functional component code example angular http pass query params code example reference c++ function parameter code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy