How to calculate average hours?

1

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

These are in DATETIME format.

I would like to run the average that they spent online, is it possible without using another programming language?

I tried something like:

SELECT AVG(hora_que_entrou - hora_que_saiu) FROM 'visitantes'

But I did not succeed.

    
asked by anonymous 26.12.2014 / 20:27

2 answers

3

Assuming that the table's composition is set up correctly would be like this using the TIMEDIFF :

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

The result is given in seconds.

    
26.12.2014 / 20:33
0

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

    
26.12.2014 / 20:33