sql >> Base de Datos >  >> RDS >> Mysql

mysql calcula los segundos entre dos fechas/horas para cada día

Use TIMESTAMPDIFF en MySQL:

SELECT TIMESTAMPDIFF(SECOND,from,to); 

Ejemplo:

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