Posted by Arjun Arjun on Saturday 4th January 2020, 1 minute read

Difference between two date in JavaScript

How to JavaScript

Let us see an example of how to calculate the difference between dates using Javascript. First, write an HTML code with Javascript as below:

const d1 = new Date("12/12/2018");
const d2 = new Date("12/12/2020");
const timeDiff = d2.getTime() - d1.getTime();
const DaysDiff = timeDiff / (1000 * 3600 * 24);
console.log("Days of difference between:"+ d1 +"
and "+d2+" is:" +DaysDiff);
...
Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.