Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
how to calculate number of months and days in javascript
Sandeep Chaurasia
Feb 2 2017 6:47 AM
232
Reply
Hi,
I want to calculate number of months and days between two dates using javascript.
Javascript
function calculate(){
var datefrom = $("#datefrom").val();
var dateto = $("#dateto").val();
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(datefrom);
var secondDate = new Date(dateto);
var days = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
console.log(days);
}
html
<p><strong>Date From:</strong><input type="text" name="datefrom" id="datefrom"></p>
<p><strong>Date To:</strong><input type="text" name="dateto" id="dateto"></p>
<p><input type="button" name="calculate" id="calculate" onclick="calculate();" value="Total"></p>
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Html Table with Data convert to String with Proper Format
Disabling and Enabling text box based on selection option