Im trying to figure out a way to get the time difference in seconds between two dates.
For example, difference in seconds between:
2013-5-11 8:37:18
2013-5-11 10:37:18
Tried:
function timeDifference(laterdate, earlierdate) {
var difference = laterdate.getTime() - earlierdate.getTime();
var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference -= hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference -= minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);
return secondsDifference;
}
But that does not work in Nodejs, error with
getTime()
function not being found
See Question&Answers more detail:os