MySQL 8.1
TIME_TO_SEC(time)Parameters
- timeTIME
- Time or datetime
Return value
An integer number of seconds, negative for a negative time; for a datetime only the time is used
Examples
Time to seconds
MySQL 8.1
SELECT TIME_TO_SEC('01:02:03');Flight duration in seconds
MySQL 8.1
SELECT id,
TIMEDIFF(time_in, time_out) AS duration,
TIME_TO_SEC(TIMEDIFF(time_in, time_out)) AS duration_sec
FROM Trip;Details
For a datetime, only the time of day is used: TIME_TO_SEC('2022-06-16 01:00:00') returns 3600. To get the number of seconds between two datetimes, use TIMESTAMPDIFF(SECOND, start, end).