0

in javascript I got two dates. How to find the difference between two dates.
var first = document.getElemetById("first_date").value;
var last = document.getElemetById("last_date").value;
the date format is mm/dd/yyyy(07/19/2015);
how to find?

3
Contributors
3
Replies
26
Views
2 Years
Discussion Span
Last Post by AntonyRayan
0

In general convert each date into a number (of hours, minutes, seconds, whatever, depending on the degree of precision that you require) and then subtract one from the other. This can be a bit tricky with leap years and whatever.

In practice it might be easiest to convert your dates into Javascript Date objects [new Date(datestring) or new Date(year, month, day, etc.)] then convert these into the internal milisecond format [getTime()] and then just subtract them. Divide the result by the appropriate value if you need less than millisecond precision.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.