
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to calculate the difference between two dates in JavaScript?
To get dates in JavaScript, use the getTime() method. Forgetting the difference between two dates, calculate the difference between date and time.
Example
You can try to run the following code to learn how to calculate a difference between two dates −
<!DOCTYPE html> <html> <body> <script> var dateFirst = new Date("11/25/2017"); var dateSecond = new Date("11/28/2017"); // time difference var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime()); // days difference var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // difference alert(diffDays); </script> </body> </html>
- Related Articles
- How to calculate minutes between two dates in JavaScript?
- How to calculate time difference between two times or dates?
- How to calculate the percentage between two dates in Excel?
- How to calculate the midpoint between two dates in Excel?
- How to calculate average between two dates in Excel?
- How to calculate the weeks and days between two dates in Excel?
- How to get the difference between two dates in Android?
- Calculate minutes between two dates in C#
- Calculate the difference between two dates in days, weeks, months and years in Excel
- C# Program to get the difference between two dates
- How to get the number of seconds between two Dates in JavaScript?
- How to get the number of days between two Dates in JavaScript?
- Get the difference between dates and calculate salary with MySQL?
- How to store all dates in an array present in between given two dates in JavaScript?
- C# Program to determine the difference in hours between two dates

Advertisements