You can test by minutes or seconds of hours:
function verificarDiferencaHorario(inicialMin, finalMin) {
var totalMin = Number(finalMin - inicialMin);
console.log(Math.trunc(totalMin / 60).toString() + ":" + (totalMin % 60).toString());
}
Supposing the times you mentioned:
function verificarHorario() {
var inicial = "11:20", final = "16:40";
var splInicial = inicial.split(":"), splFinal = final.split(":");
var inicialMin = (Number(splInicial[0] * 60)) + Number(splInicial[1]);
var finalMin = (Number(splFinal[0] * 60)) + Number(splFinal[1]);
verificarDiferencaHorario(inicialMin, finalMin);
}
The same goes for days: the last conversion in minutes and the function checkDiferencaHorario returns in hours and minutes the difference.
Add your code @Newtech!
– Marconi
Sorry! I updated the question to make it easier to understand.
– usuario
var dtPartida = 20/06/2017 11:20 ??
– user60252
@Leocaracciolo Sim
– usuario
edited the answer, see there
– user60252
@Leocaracciolo Stayed show. You know if you have how to return like this: 5h 20m?
– usuario
see there in response
– user60252
What is the format of the date to be processed? by the chosen answer I think it was doubtful if it is 20170620 11:20 or as you said in the comment "@Leocaracciolo Yes - Newtech 7 hours ago". Of qq way to return (5h 20m) it was only to remove the : (two points)there of the expression and to give a space var s = Math.floor(d.asHours()) + "h" + Moment.utc(ms). format(" mm") +"m"; re-edited the response
– user60252