Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

mysql calcula segundos entre duas datas/horas para cada dia


Use TIMESTAMPDIFF no MySQL:
SELECT TIMESTAMPDIFF(SECOND,from,to); 

Exemplo:
SELECT TIMESTAMPDIFF(SECOND,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 864000
SELECT TIMESTAMPDIFF(MINUTE,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 14400
SELECT TIMESTAMPDIFF(HOUR,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 240
SELECT TIMESTAMPDIFF(DAY,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 10