You have two columns of the type
datetimes and you want to calculate the difference between them.
SELECT TIMESTAMPDIFF(SECOND, StartTime, EndTime) AS difference FROM Table;
To get the difference between the
datetimes in MySQL, use the
TIMESTAMPDIFF(unit, start, end) function. The unit argument can be
YEAR. To get the difference in seconds as we have done here, choose
SECOND. To get the difference in minutes, choose
MINUTE; for the difference in hours, choose
HOUR, etc. The end and the start arguments are the ending timestamp and the starting timestamp, respectively (here,
SEC_TO_TIME() returns a time value by converting the seconds specified in the argument. The return value is in hours, minutes and seconds. The range of the result is in the time data type.
STR_TO_DATE("2022-12-30 12:12:12", "%Y-%m-%d %H:%i:%s")