- Related Questions & Answers
- Calculate minutes between two dates in C#
- How to get the difference between two dates in Android?
- C# Program to get the difference between two dates
- Get the difference between dates and calculate salary with MySQL?
- Not able to get the difference between two dates (SAP)
- C# Program to determine the difference in hours between two dates
- C# Program to get the difference between two dates in seconds
- C Program to calculate the difference between two time periods
- How do I calculate number of days between two dates using Python?
- How to get the number of seconds between two Dates in JavaScript?
- How to get the number of days between two Dates in JavaScript?
- How can I calculate full 24hour days between two specified dates in MySQL?
- How can we calculate the difference between two time values in MySQL?
- C++ Program to Calculate Difference Between Two Time Period
- How to get the differences between two dates in iOS?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To get dates in JavaScript, use the getTime() method. Forgetting the difference between two dates, calculate the difference between date and time.

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>

Advertisements