
- 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 get the number of days between two Dates in JavaScript?
To get the number of days between two dates, use the Maths.floor() method.
Example
You can try to run the following code to get days between two dates −
<html> <head> <title>JavaScript Get Days</title> </head> <body> <script> var date1, date2; date1 = new Date(); document.write(""+date1); date2 = new Date( "Dec 10, 2015 20:15:10" ); document.write("<br>"+date2); // get total seconds between two dates var res = Math.abs(date1 - date2) / 1000; var days = Math.floor(res / 86400); document.write("<br>Difference: "+days); </script> </body> </html>
Output
Mon May 28 2018 09:32:56 GMT+0530 (India Standard Time) Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Difference: 899
- Related Articles
- How do I get the number of days between two dates in JavaScript?
- Finding Number of Days Between Two Dates JavaScript
- 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?
- Find number of days between two given dates in C++
- Python program to find number of days between two given dates
- How to get number of quarters between two dates in Java
- How to count days between two dates in Java
- How do I calculate number of days between two dates using Python?
- How to calculate the weeks and days between two dates in Excel?
- How to get the difference between two dates in Android?
- How to get the differences between two dates in iOS?
- How to calculate the difference between two dates in JavaScript?
- How to calculate minutes between two dates in JavaScript?
- How to get the differences between two dates in Android using Kotlin?

Advertisements