You can use TIMEDIFF() and TIME_TO_SEC() functions as follows:
SELECT TIME_TO_SEC(TIMEDIFF('2010-08-20 12:01:00', '2010-08-20 12:00:00')) diff; +
You can also use the UNIX_TIMESTAMP() function as @Amber suggested in another answer:
SELECT UNIX_TIMESTAMP('2010-08-20 12:01:00') - UNIX_TIMESTAMP('2010-08-20 12:00:00') diff; +
If you are using the TIMESTAMP data TIMESTAMP , I think the UNIX_TIMESTAMP() solution will be a little faster, since the TIMESTAMP values ββare already stored as an integer representing the number of seconds since ( Source ). Quoting docs :
When UNIX_TIMESTAMP() used in the TIMESTAMP column, the function returns the value of the internal timestamp directly, without any implicit conversion of "string-to-Unix-timestamp".
Keep in mind that TIMEDIFF() returns a TIME data type . TIME values ββcan vary from '-838: 59: 59' to '838: 59: 59' (approximately 34.96 days)
Daniel Vassallo Aug 20 2018-10-10T00: 00Z
source share