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

Question:

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

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

This doesn't work, it just calculates minutes between 2 different hours.

Answer:

StackOverflow original answer

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.
Scroll to Top