How would you check time difference from two text-boxes in Javascript?
When i tried the difference between same time stamp it gave 0 Days 5 Hours 30 Minutes
so to get it exactly i have subtracted 5 hours and 30 min
function get_time_diff( datetime )
{
var datetime = typeof datetime !== 'undefined' ? datetime : "2014-01-01 01:02:03.123456";
var datetime = new Date(datetime).getTime();
var now = new Date().getTime();
if( isNaN(datetime) )
{
return "";
}
console.log( datetime + " " + now);
if (datetime < now) {
var milisec_diff = now - datetime;
}else{
var milisec_diff = datetime - now;
}
var days = Math.floor(milisec_diff / 1000 / 60 / (60 * 24));
var date_diff = new Date( milisec_diff );
return days + "d "+ (date_diff.getHours() - 5) + "h " + (date_diff.getMinutes() - 30) + "m";
}