Can any one suggest a jQuery plugin for calculating the difference between two dates (dates may contain time also) and show it as \'32 days\', \'13 hours\', \'20 min\' etc?<
Here's a pretty simple Javascript implementation I just hacked up. You can do the math to extend this to months or years or remove the plurals for 1 values if needed.
var dateDiff = function ( d1, d2 ) {
var diff = Math.abs(d1 - d2);
if (Math.floor(diff/86400000)) {
return Math.floor(diff/86400000) + " days";
} else if (Math.floor(diff/3600000)) {
return Math.floor(diff/3600000) + " hours";
} else if (Math.floor(diff/60000)) {
return Math.floor(diff/60000) + " minutes";
} else {
return "< 1 minute";
}
};
dateDiff(new Date(1990, 1, 1), new Date(1990, 1, 13)) // -> 12 days