TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sandeep Chaurasia
NA
38
7.9k
how to calculate number of months and days in javascript
Feb 2 2017 6:47 AM
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>
Reply
Answers (
2
)
Html Table with Data convert to String with Proper Format
Disabling and Enabling text box based on selection option