How to calculate the difference in hours between these dates? MySQL

6

The starting time and date is: 2007-12-31 23:59:59 and the end time is: 2018-03-06 17:44:09, I want to calculate the difference of hours between these dates. I thought that with the hour it was enough, but no, you have to calculate the days too

select TIMESTAMPDIFF(MINUTE, notificacion_update, now()) as horas from notificacion;

This does not work, just calculate minutes between 2 different hours.

    
asked by Ricardo Sauceda Rojas 06.03.2018 в 19:23
source

1 answer

7

Original answer from StackOverflow

SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');
-- result: 22:00:59.


SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
-- result: 79259  the difference in seconds with the time.
    
answered by 06.03.2018 / 19:26
source