Mysql
 sql >> Base de données >  >> RDS >> Mysql

mysql calcule les secondes entre deux dates/heures pour chaque jour

Utilisez TIMESTAMPDIFF dans MySQL :

SELECT TIMESTAMPDIFF(SECOND,from,to); 

Exemple :

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