In Javascript (and in most languages, in fact), dates and times are represented in memory as the number of milliseconds from an arbitrary date-time. You can see this number when using the function getTime like Date, like this:
var agora = new Date();
agora.getTime();
So to know how long a call took, you can do the following:
var horaEntrada = foo;
var horaSaida = bar;
var tempoAtendimentoEmMilissegundos = bar.getTime() - foo.getTime();
Just swap foo
and bar
the actual times of entry and exit.
If you want to convert call time to other units of measurement, it’s easy:
var tempoAtendimentoEmSegundos = tempoAtendimentoEmMilissegundos / 1000;
var tempoAtendimentoEmMinutos = tempoAtendimentoEmSegundos / 60;
// etc., etc.
Finally, to get the average, just make a simple account. Accumulate all times in a sum, and divide the sum by the amount of calls.
var soma = 0;
for (let i = 0; i < tempos.length; i++) {
soma += tempos[i];
}
var media = soma / tempos.length;
It is not easier to do this calculation directly in the database?
– Sorack
@Sorack may be too, but I didn’t know it was possible to do it directly from the bank
– Rafael Augusto
Put here what your bank and more or less the structure of your table we can give an answer based on this
– Sorack
@Sorack Atualizei
– Rafael Augusto