- Related Questions & Answers
- How to get the number of days between two Dates in JavaScript?
- 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 find the number of days and number of weeks between two dates in R?
- How do I generate days from the range of dates in MySQL?
- How to get number of quarters between two dates in Java
- How to count days between two dates in Java
- How can I calculate full 24hour days between two specified dates in MySQL?
- Find the number of logins between two dates in MySQL
- How to get the differences between two dates in iOS?
- How to get the difference between two dates in Android?
- Get the SUM of records between two given dates in MySQL
- How to calculate the difference between two dates in JavaScript?
- C# Program to get the difference between two dates
- Get the number of days between current date and date field?

- 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. For getting the difference, calculate the difference between dates.

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("10/29/2017"); var dateSecond = new Date("10/18/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