How to calculate average time?

Asked

Viewed 770 times

1

I have a table named visitantes in it I insert the hora_que_entrou and the hora_que_saiu of my user on my website.

These are in format DATETIME.

I would like to run the average they passed onlines, it is possible this without resorting to another programming language?

I tried something like:

SELECT AVG(hora_que_entrou - hora_que_saiu) FROM `visitantes`

But I didn’t succeed.

  • You had question about the result and then deleted. I edited to complement what you had asked.

  • But this p/ accept if given.

2 answers

4

Assuming that the composition of the table is configured correctly would be so using the function TIMEDIFF:

SELECT AVG(TIMEDIFF(hora_que_entrou, hora_que_saiu)) FROM `visitantes`

I put in the Github for future reference.

The result is given in seconds.

0

You can try casting dates for a team and try to subtract.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.