Quantcast
Channel: How do I get the difference between two Dates in JavaScript? - Stack Overflow
Viewing all articles
Browse latest Browse all 20

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

$
0
0

Below code will return the days left from today to futures date.

Dependencies: jQuery and MomentJs.

var getDaysLeft = function (date) {  var today = new Date();  var daysLeftInMilliSec = Math.abs(new Date(moment(today).format('YYYY-MM-DD')) - new Date(date));  var daysLeft = daysLeftInMilliSec / (1000 * 60 * 60 * 24);     return daysLeft;};getDaysLeft('YYYY-MM-DD');

Viewing all articles
Browse latest Browse all 20

Trending Articles