Have you tried using TIMESTAMPDIFF(Unit, datetime1, datetime2)? It returns the subtraction of datetime2- datetime1 and Unit may be SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR
follows syntax:
SELECT TIMESTAMPDIFF(MONTH,'2009-05-18','2009-07-29');
will return 2
SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');
will return 128885, or in your case
SELECT TIMESTAMPDIFF(MINUTE, t.login, t.logout)
from tabela t
where user_id = id_do_usuario;
this will return in minutes the time there is only treat or would give to return already in the query also:
SELECT CONCAT(FLOOR(TIMESTAMPDIFF(MINUTE, t.login, t.logout) /60), 'hr', MOD(TIMESTAMPDIFF(MINUTE, t.login, t.logout), 60),'m') as tempo_logado
from tabela t where user_id = id_do_usuario;
Reference: Mysql 5.5 Reference Manual / Functions and Operators / Date and Time Functions
I hope I’ve helped.
You can show the select you’ve already made?
– rray
Nelson, good afternoon.
– Humberto
Nelson, the problem is that I have multiple user inputs and outputs during the day, I would need to align each t.login with your subsequent t.logout for the query to run and calculate the time difference between login and logout.
– Humberto
Dude what you could do is use the SUM(), along with those examples there and there is no clause Where you put one more and data = now() there is to solve
– Nelson Aguiar