Mysql
 sql >> Database >  >> RDS >> Mysql

mysql calcola i secondi tra due date/ora per ogni giorno

Usa TIMESTAMPDIFF in MySQL:

SELECT TIMESTAMPDIFF(SECOND,from,to); 

Esempio:

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