Quantcast
Viewing latest article 12
Browse Latest Browse All 20

Answer by sparkyspider for How do I get the difference between two Dates in JavaScript?

Depending on your needs, this function will calculate the difference between the 2 days, and return a result in days decimal.

// This one returns a signed decimal. The sign indicates past or future.this.getDateDiff = function(date1, date2) {    return (date1.getTime() - date2.getTime()) / (1000 * 60 * 60 * 24);}// This one always returns a positive decimal. (Suggested by Koen below)this.getDateDiff = function(date1, date2) {    return Math.abs((date1.getTime() - date2.getTime()) / (1000 * 60 * 60 * 24));}

Viewing latest article 12
Browse Latest Browse All 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>