вариант #2
function dateDiff( date1, date2 ) {
date1 = new Date( date1 );
date2 = new Date( date2 );
var milliseconds = date2.getMilliseconds() - date1.getMilliseconds();
if ( milliseconds < 0 ) {
milliseconds += 1000;
date2.setSeconds( date2.getSeconds() - 1 );
}
var seconds = date2.getSeconds() - date1.getSeconds();
if ( seconds < 0 ) {
seconds += 60;
date2.setMinutes( date2.getMinutes() - 1 );
}
var minutes = date2.getMinutes() - date1.getMinutes();
if ( minutes < 0 ) {
minutes += 60;
date2.setHours( date2.getHours() - 1 );
}
var hours = date2.getHours() - date1.getHours();
if ( hours < 0 ) {
hours += 24;
date2.setDate( date2.getDate() - 1 );
}
var days = date2.getDate() - date1.getDate();
if ( days < 0 ) {
days += new Date( date2.getFullYear(), date2.getMonth() - 1, 0 ).getDate() + 1;
date2.setMonth( date2.getMonth() - 1 );
}
var months = date2.getMonth() - date1.getMonth();
if ( months < 0 ) {
months += 12;
date2.setFullYear( date2.getFullYear() - 1 );
}
var years = date2.getFullYear() - date1.getFullYear();
return [ years, months, days, hours, minutes, seconds, milliseconds ];
}
alert( dateDiff( '2013-01-10 00:10', '2013-01-11 00:09' ) );
alert( dateDiff( '2013-04-10', '2013-10-20' ) );