Find the difference between two dates in days, hours and minutes javascript. Through this tutorial, i am going to show you how to find difference between two dates and get the difference in days, hours, minutes.

## Find the difference between two dates in the following

- javascript difference between two dates in days
- calculate the difference between two dates in hours javascript
- javascript difference between two dates in minutes

### 1 – javascript difference between two dates in days

Use the following function to calculate the difference between 2 dates and get difference days; as shown below:

function daysDiff(dt1, dt2) { // calculate the time difference of two dates JavaScript var diffTime =(dt2.getTime() - dt1.getTime()); // calculate the number of days between two dates javascript var daysDiff = diffTime / (1000 * 3600 * 24); return daysDiff; }

See the following example to calculate the difference between 2 dates and get difference days; as shown below:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>calculate difference between two dates in days javascript</title> </head> <body> <script type = "text/javascript"> function daysDiff(dt1, dt2) { // calculate the time difference of two dates JavaScript var diffTime =(dt2.getTime() - dt1.getTime()); // calculate the number of days between two dates javascript var daysDiff = diffTime / (1000 * 3600 * 24); return daysDiff; } dt1 = new Date("2019-11-27"); dt2 = new Date("2019-11-29"); var days = daysDiff(dt1, dt2) document.write( "calculate difference between two dates in days javascript :- " + days ); </script> </body> </html><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>calculate difference between two dates in days javascript</title> </head> <body> <script type = "text/javascript"> function daysDiff(dt1, dt2) { // calculate the time difference of two dates JavaScript var diffTime =(dt2.getTime() - dt1.getTime()); // calculate the number of days between two dates javascript var daysDiff = diffTime / (1000 * 3600 * 24); return daysDiff; } dt1 = new Date("2019-11-27"); dt2 = new Date("2019-11-29"); var days = daysDiff(dt1, dt2) document.write( "calculate difference between two dates in days javascript :- " + days ); </script> </body> </html>

### 2 – Calculate the difference between two dates in hours javascript

Use the following function to find difference between 2 dates and get a different hours; as shown below:

function hoursDiff(dt1, dt2) { // calculate the time difference of two dates JavaScript var diffTime =(dt2.getTime() - dt1.getTime()); // calculate the number of days between hours dates javascript var hoursDiff = diffTime / (1000 * 3600); return hoursDiff; }

Use the following example to find difference between 2 dates and get a different hours; as shown below:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>calculate difference between two dates in hours javascript</title> </head> <body> <script type = "text/javascript"> function hoursDiff(dt1, dt2) { // calculate the time difference of two dates JavaScript var diffTime =(dt2.getTime() - dt1.getTime()); // calculate the number of days between hours dates javascript var hoursDiff = diffTime / (1000 * 3600); return hoursDiff; } dt1 = new Date("2019-11-27"); dt2 = new Date("2019-11-29"); var hours = hoursDiff(dt1, dt2) document.write( "calculate difference between two dates in hours javascript :- " + hours ); </script> </body> </html>

### 3 – javascript difference between two dates in minutes

Use the following function to find the difference between 2 dates and get difference minutes; as shown below:

function minutesDiff(dt1, dt2) { var diffMin =(dt2.getTime() - dt1.getTime()) / 1000; diff /= 60; return Math.abs(Math.round( diffMin )); }

Use the following example to find the difference between 2 dates and get difference minutes; as shown below:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>calculate difference between two dates in minutes javascript</title> </head> <body> <script type = "text/javascript"> function minutesDiff(dt1, dt2) { var diffMin =(dt2.getTime() - dt1.getTime()) / 1000; diff /= 60; return Math.abs(Math.round( diffMin )); } dt1 = new Date("2019-11-27"); dt2 = new Date("2019-11-28"); var minutes = minutesDiff(dt1, dt2) document.write( "calculate difference between two dates in minutes javascript :- " + minutes ); </script> </body> </html>

## Recommended JavaScript Tutorials

**Recommended:-**JavaScript Get Date Methods with Example

**Recommended:-**JavaScript Set Date Methods

**Recommended:-**JavaScript getUTCFullYear Method

**Recommended:-**javaScript date.getUTCmonth Method with Examples

**Recommended:-**JavaScript getUTCDate() Method with Example

**Recommended:-**javaScript getUTCDay() Method

**Recommended:-**JavaScript setUTCFullYear() Method

**Recommended:-**JavaScript setUTCMonth() Method

**Recommended:-**JavaScript Date setUTCDate() Method

**Recommended:-**JavaScript Date.setUTCHours() Method

**Recommended:-**JavaScript: date.setUTCMinutes() Method with Example

**Recommended:-**JavaScript setUTCSecond() Method

**Recommended:-**JavaScript Date.setUTCmilliseconds Method

**Recommended:-**JavaScript Get Current Year 2, 4 Digit

**Recommended:-**JavaScript Get Month in 2 Digit

**Recommended:-**JavaScript Call Function After Whole Page Load

**Recommended:-**JavaScript Find Position of Element in Array

**Recommended:-**JavaScript Concat or Merge Array

**Recommended:-**How to Check If Object is Array in JavaScript

**Recommended:-**JavaScript Find Max and Min Value from an Array

**Recommended:-**JavaScript Find First Occurrence in Array

**Recommended:-**JavaScript Find First Element Position In Array

**Recommended:-**JavaScript Check if an Array Contains a Value

**Recommended:-**JavaScript: Array every() method

**Recommended:-**JavaScript Array Reduce Method with Example

**Recommended:-**How to Use Array map() Method in JavaScript

**Recommended:-**JavaScript Array forEach – Loop Through an Array

**Recommended:-**JavaScript Convert Array to JSON Object

**Recommended:-**JavaScript Remove Duplicates From Array

**Recommended:-**JavaScript Multidimensional Array Push Pop

**Recommended:-**JavaScript Sum Array and Array Of Object

## Be First to Comment